View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
pikapika13[_26_] pikapika13[_26_] is offline
external usenet poster
 
Posts: 1
Default Repost--"Ignore spaces and tabs in word search"


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.


' 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

--
pikapika1
-----------------------------------------------------------------------
pikapika13's Profile: http://www.excelforum.com/member.php...fo&userid=1089
View this thread: http://www.excelforum.com/showthread.php?threadid=57086