• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • 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
 
GrahamSkanRetiredCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
jlspencerAuthor Commented:
Worked like a charm
0
 
GrahamSkanRetiredCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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