Solved

macro conversion from MS  Word 2000  to MS Word 2010

Posted on 2011-02-17
6
621 Views
Last Modified: 2012-05-11
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
Comment
Question by:jlspencer
  • 4
  • 2
6 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 34923948
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
 

Author Comment

by:jlspencer
ID: 34926851
This is the result of running the above code


Runtime error 5941

The requested member of the collection does not exist.
0
 

Assisted Solution

by:jlspencer
jlspencer earned 0 total points
ID: 34927866
I removed the everything after :

SaveWithDocument _:=True  


Basically the Range information. Now it works fine
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:jlspencer
ID: 34927904
Worked like a charm
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34929078
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
 

Author Closing Comment

by:jlspencer
ID: 34959165
I had to modify the script to get it to work correctly
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question