Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding in Word VBA (2000,XP)

    Hi there!

    ###Edited: Never mind, I've decided to do the searching entirely within VBA.###

    As an XL MVP I know almost nothing about the Word object model and all of it's trickery.

    I want to edit an HTML document in Word through automation from XL.

    What I need to do is:

    - find the first occurance of the string <x:excelname>
    - find the LAST occurance of the string </x:excelname>

    BETWEEN those two:

    - find <x:name>
    - get all characters until the next occurance of </x:name>

    - replace those characters with another string
    - find the next <x:name> and repeat the above.

    clear as mud?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Finding in Word VBA (2000,XP)

    To get the HTML version of a word document you can use a syntax like
    strHTML = doc.HTMLProject.HTMLProjectItems(1).Text

    I once wrote some code that broke this into tokens by iteratively calling a routine that returned the next token and a pointer to how far through the string we have got so far, I can post some sample code if that would help.

    StuartR

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding in Word VBA (2000,XP)

    > clear as mud?

    Let's do some mud-wrestling.
    How about two wildcard matches:

    1) Find what: <x:excelname>*</x:excelname>
    This will select the whole element <x:excelname>.

    2) Search downwards (that is, only in the selected text)
    Find what: (<x:name>)*(</x:name>)
    Replace with: 1new_text2
    "Replace all" will replace the contents of all <x:name> elements in <x:excelname> with "new_text".

    If the new_text depends on what was in <x:name> before, things would get a bit more complicated.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding in Word VBA (2000,XP)

    Hi Stuart and Clause,

    Sorry if my edit was unclear.

    I have decided to read the file I want to do the searching in into VBA using Line Input statements and do the finding from there.

    So subject closed.

    Thanks anyway.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Finding in Word VBA (2000,XP)

    Ah, but you missed the fun of Find in Word, it became an Object with several zillion properties. Line Input was a good choice: Word's object model makes this Excel programmer <img src=/S/flee.gif border=0 alt=flee width=25 height=25>.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding in Word VBA (2000,XP)

    In Word/VBA, I usually read everything into a big string. After all, those beasties can be up to 2 GBytes in size, and especially for XML and other formats that aren't line oriented, it greatly simplifies further processing.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

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