Consulting

Results 1 to 3 of 3

Thread: Instructions - Tutorials

  1. #1

    Instructions - Tutorials

    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:

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

    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.

  2. #2
    OK - i have had a play and found this - whihc seems to work ok:

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

    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.


  3. #3
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Don,

    Your solution to the coding issue is approriate.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •