×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

word 2010 run-time error '91' but works on windows 7

word 2010 run-time error '91' but works on windows 7

word 2010 run-time error '91' but works on windows 7

(OP)
We have an add-in that lists names of bookmarks that the user selects and it pastes the bookmark into the current document. this has been working fine on a windows 7 pc running word 2010. when we run it on a windows 10 pc with word 2010 we get a runtime error '91' object variable or with block variable not set. Any help with will be appreciated as it was written by an ex employee and I have very little VBA experience.

CODE -->

Sub STC161()
    setvariables
AppCond "STC161", STcond
End Sub
Sub STC162()
    setvariables
AppCond "STC162", STcond
End Sub

Sub AppCond(varbkmrk, doclocation)
'
' AppCond Macro
'
 Documents.Open filename:=doclocation, _
 ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
        WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
        wdOpenFormatAuto
    Selection.GoTo What:=wdGoToBookmark, Name:=varbkmrk
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Copy
    ActiveWindow.Close
    Selection.EndKey Unit:=wdStory
    Selection.Paste
    Selection.fields.Update
    Selection.EndKey Unit:=wdStory

End Sub

Sub setvariables()

STcond = "c:\Template\book marks\book marks conditions.doc"

End Sub 

RE: word 2010 run-time error '91' but works on windows 7

Before the first line of the code you posted, you should have a line like:
Dim STcond As String
Otherwise, the rest of your code won't know what refers STcond to. As for STCond itself, that refers to a file named:
c:\Template\book marks\book marks conditions.doc
You need to ensure that file is in the specified location; even the extension must remain the same or the code must be changed to suit.

As for the overall code, much of it is pointless. Try:

CODE

Option Explicit
Const STcond As String = "c:\Template\book marks\book marks conditions.doc"

Sub STC161()
Call AppCond("STC161", STcond)
End Sub

Sub STC162()
Call AppCond("STC162", STcond)
End Sub

Sub AppCond(varbkmrk, doclocation)
Application.ScreenUpdating = False
Dim DocTgt As Document, DocSrc As Document
Set DocTgt = ActiveDocument
Set DocSrc = Documents.Open(FileName:=doclocation, ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)
With DocTgt
  .Range.Characters.Last.FormattedText = DocSrc.Bookmarks(varbkmrk).Range.FormattedText
  DocSrc.Close False
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub 

Cheers
Paul Edstein
[MS MVP - Word]

RE: word 2010 run-time error '91' but works on windows 7

(OP)
Thanks Paul, works great.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close