Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2014, 08:33 PM
Jmanville Jmanville is offline VBA find keyword and move to location then add symbol Windows Vista VBA find keyword and move to location then add symbol Office 2007
Novice
VBA find keyword and move to location then add symbol
 
Join Date: Oct 2014
Posts: 2
Jmanville is on a distinguished road
Default VBA find keyword and move to location then add symbol

I need to use VBA in word to firstly match (find) a word in a given document, from a external text file, then move to the right 5 words from the matched word to the end of that word and then at that point insert a symbol and then resume with the next word in the text file, running this all from a macro. The purpose of this is to use a text file to find key words in a document, then in the document move a few words further along and enter a tick before reading the next key word and repeating until the EOF. I can read the file, find the word but cannot then move the cursor to the right and add the symbol only once. It moves the required amount of words but then I seem to get multiple ticks rather than just one for each key word. I just want one tick for each key word 5 words away, reading from a text file.
Reply With Quote
  #2  
Old 10-21-2014, 12:01 AM
macropod's Avatar
macropod macropod is offline VBA find keyword and move to location then add symbol Windows 7 64bit VBA find keyword and move to location then add symbol Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You don't need to move the cursor. All you need do is tell Word how many words after the found one to insert the symbol. Without seeing the relevant part of your code, tbough (and there are plenty of examples on the forum for using content in one file to Find/Replace in another), I can't say which approach to that is best suited to what you're using. It could, for example, be achieved by a carefully crafted Find/Replace expression without the need to change anything else about or code or, perhaps, by some other change to your code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-21-2014, 11:36 PM
Jmanville Jmanville is offline VBA find keyword and move to location then add symbol Windows Vista VBA find keyword and move to location then add symbol Office 2007
Novice
VBA find keyword and move to location then add symbol
 
Join Date: Oct 2014
Posts: 2
Jmanville is on a distinguished road
Default Your response

Thank you for your help. I have the file opening and reading the words, even find them and adding the tick directly after the found word but have not managed to work out how to put the tick 5 words away. What I have not mastered I guess is the "carefully crafted find and replace expression" that will move the tick 5 words away. Is it possible you could explain the code to me further? I could put the code I have here if that would help. The examples I have found so far are for finding and replacing the word in the document with the word in the file which I do not need as the original word needs to remain in the document not be replaced with anything. I need only to insert the tick when the word is found but not directly next to it. Down a line would be ok, just not immediately next to it. At the moment the code uses the replace statement to replace the word found (with itself) and concatenate the tick immediately after as part of the replace statement and then move on to the next word in the file within the read loop. I located an example to move right 5 words but ended up with multiple ticks all in the same place after the first word was found.
Reply With Quote
  #4  
Old 10-22-2014, 01:45 AM
macropod's Avatar
macropod macropod is offline VBA find keyword and move to location then add symbol Windows 7 64bit VBA find keyword and move to location then add symbol Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could, for example, use a wildcard Find/Replace, using:
Code:
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = StrTxt & "[,. ]@<*>[,. ]@<*>[,. ]@<*>[,. ]@<*>[,. ]@"
    .Replacement.Text = "^&" & Chr(123)
    .Forward = True
    .Wrap = wdFindcontue
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
where StrTxt is the word to find and Chr(123) is the symbol you want to add.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA find keyword and move to location then add symbol how to find and replace a symbol with another symbol wondermuse Word 5 10-09-2014 06:30 AM
VBA find keyword and move to location then add symbol Move shape to bookmark location Byron Polk Word VBA 4 08-07-2014 03:21 AM
VBA find keyword and move to location then add symbol How to either move document display to right or left; or reduce size of find/replace window. pmstock Word 2 08-02-2014 08:34 PM
VBA find keyword and move to location then add symbol Find keyword in section & delete section donaldadams1951 Word VBA 5 12-03-2013 10:08 AM
Move pst location? markg2 Outlook 0 06-29-2013 11:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft