Repost--"Ignore spaces and tabs in word search"

P

pikapika13

Let me post this again because I don't think I explained this well th
first go around:
The code below opens up a word doc, looks for the word "Primary Key:
then gives me the corresponding answer. However, I require a twea
since there are times when the word "Primary Key:" is followed b
unwanted spaces, no spaces, or tabs. It works great if there is on
space, but it doesn't work if there are no spaces after the colon, o
there are more than one space.
I have marked the problem area with UPPER CASE comments.

I have tried tweaking the code myself, but I'm new to this VBA.
:confused:

' Get Word doc
'strDoc = "C:\MyDocName"
strDoc = "C:\Documents and Settings\edward.millis\Desktop\TestDoc.doc"
Set docWord = appWord.Documents.Open(strDoc)
' Set Word range
Set rngWord = docWord.Content
' Find first term
rngWord.Find.Execute _

'******PROBLEM STARTS HERE***********
FindText:="Primary Key:", MatchWildcards:=False, _
Wrap:=wdFindStop, Forward:=True
' Reset range to get number
rngWord.Collapse wdCollapseEnd
Do
rngWord.MoveStart Unit:=wdCharacter, Count:=1
numKey = Trim(rngWord.Text)
Loop Until Right(numKey, 1) <> " "
rngWord.MoveEnd Unit:=wdWord, Count:=1
' Put number into variable
numKey = Trim(rngWord.Text
 
D

Dave Peterson

Why not post in one of the MSWord newsgroups?

Then you can take the response and tweak it to run from excel.
 

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