Macro not working in Word 2003

R

Roger Marrs

Using the code below in Word 2000 a macro I was using worked just fine.
After upgrading to Word 2003 it no longer works correctly. In fact if I
execute the macro on a table with more than one row in it, the screen just
starts flashing and I have to halt Word with the task manager.

Here's the code:
Dim marker As String
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
Do While .Execute(FindText:="", _
Wrap:=wdFindStop, Forward:=True) = True
marker = Selection.Text
Selection.Delete
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_ PreserveFormatting:=False
Selection.TypeText Text:="INCLUDETEXT " & Chr(34) &
"I:/htltr/jdltr/prod/" & marker & ".doc" & Chr(34) & " B" & marker
Selection.MoveRight wdCharacter, 2
ActiveWindow.View.ShowFieldCodes = Not
ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = Not
ActiveWindow.View.ShowFieldCodes
Loop
End With
ActiveDocument.Fields.Update

Here's what I see happening when I execute that code:
Example, I have a table with two rows, both of which are highlighted:
2136
2130
The macro selects 2136 and replaces it with:
{INCLUDETEXT I:/htltr/jdltr/prod/2136 .doc B2136 }then (I think) it selects
2130 but replaces it with:
{INCLUDETEXT I:/htltr/jdltr/prod/ .doc B }
and then the screen just keeps flashing requiring me to open the task
manager and end Word.

If I have a single row table, such as:
2136
Then the macro selects 2136 and replaces it with:
{INCLUDETEXT I:/htltr/jdltr/prod/2136 .doc B2136 }
and then ends normally, instead of going into a continuous loop. However,
that results in a filename error because the macro is inserting a " " (blank
space) between the filename and the .doc extention.

Any suggestions or assistance correcting this problem would be greatly
appreciated.
Thanks,
Roger
 
D

dennis

Well, I'm not super-proficient at VB, but I am currently
doing nearly the same thing. But I use a different
methodology that works well:

- select the existing special field (Range.Select, you get
the idea)

Then I just perform the following:

With Selection
.InsertFile FileName:=extractedFilePath, _
ConfirmConversions:=False, link:=True
End With

This inserts an INCLUDETEXT field automatically. The
"extractedFilePath" is a string var that I have manipulated
outside this method to get exactly what I want. It's then
"ready to go" for the InsertFile statement. Setting
"Link:=True" creates the INCLUDETEXT type.

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top