• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

macro conversion from MS Word 2000 to MS Word 2010

Any ideas as to why the following script will not work in MS Word 2010 This does work in MS Word 2000. It errors on line 3 with indicating a problem with bookmark.  This is a new PC Windows 7 Office 2010 that replaced  Windows 2000 Office 2000. I moved all word docs and template files to the same location on the new PC.

Sub GoFormal()
    Selection.GoTo What:=wdGoToBookmark, Name:="Signature"
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.InlineShapes.AddPicture FileName:= _
        "C:\Document\Templates\Formal.bmp", LinkToFile:=False, SaveWithDocument _
        :=True
End Sub
0
jlspencer
Asked:
jlspencer
  • 4
  • 2
2 Solutions
 
GrahamSkanCommented:
What is the error message?

Incidentally the Selection.Find object doesn't seem to do anything.

This code should do what yours seems to be trying to achieve.
Sub GoFormal()
    With ActiveDocument
     .InlineShapes.AddPicture FileName:= _
            "C:\Document\Templates\Formal.bmp", LinkToFile:=False, SaveWithDocument _
            :=True, Range:=.Bookmarks("Signature").Range
    End With
End Sub

Open in new window

0
 
jlspencerAuthor Commented:
This is the result of running the above code


Runtime error 5941

The requested member of the collection does not exist.
0
 
jlspencerAuthor Commented:
I removed the everything after :

SaveWithDocument _:=True  


Basically the Range information. Now it works fine
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
jlspencerAuthor Commented:
Worked like a charm
0
 
GrahamSkanCommented:
The code required the bookmark to know where in the document to to place the picture. If it is going where you need it anyway, then the missing bookmark was unnecessary.
0
 
jlspencerAuthor Commented:
I had to modify the script to get it to work correctly
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now