PDA

View Full Version : Instructions - Tutorials



Donquick
03-28-2011, 02:27 AM
Hi everybody,

I am doing a fair bit of integration between Excel and Word. Ususally it is excel macros opening and dealing with word docs and then returning control to excel. I am also doing some straight word macros as well.

I am reasonable new to all this and there seems to be a recurring source of confusion (and frustration) for me. That is the selection of text within word docs directly and via excel. I thought i had understood ranges in word, but then began to realise that the object model changes once you try to do the same thing from excel. as for the selection method, i just can't seem to tame that at all.

Two questions really - Firstly, are there any good books or online resources recommended by the programming community which can actually teach me all this stuff from the beginning - so i get it right and don't get into too many bad habits. I am happy to spend a few quid for the right resource.

Secondly, can somebody tell me how to use the find and replace on a word document from excel. I can do it using this:

For Each rngStory In objWdDoc.StoryRanges
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<<Ref>>"
.Replacement.Text = IRef
.Execute Replace:=wdReplaceAll
End With
Next rngStory


But how do i do it just on the main body of text rather than running through all the story ranges? I have tried something like this: objWdDoc.Application.Selection.WholeStory but i can't get it to work becuase i don't understand whether selection is an object, an area of the doc or what type of animal it is.

Sorry this is all a bit garbled, but any help would be great, thanks.

Donquick
03-28-2011, 02:41 AM
OK - i have had a play and found this - whihc seems to work ok:


With objWdDoc.Content.Find
.Text = "<<Address_1>>"
.Replacement.Text = Address
.Execute Replace:=wdReplaceAll
End With


I think i had the replace scope instruction wrong which is why i had trouble earlier. Not sure is this si the understood method or not.

:)

macropod
03-29-2011, 09:23 PM
Hi Don,

Your solution to the coding issue is approriate.