Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Need tweak in program: finding next data
An "Ed" helped me on this before. It would be nice for him to reply, but I'll take any help. The code below fetches specific data for me. However, some of the documents have extra spaces (sometimes 2,3,4 + or even tabs)after "Primary Key:" & "Table Name:" In another situation, there isn't a space after these terms and the code below seems to delete the first character right after the colon. Can someone add this modification? Sub Foo_doWord() Dim appWord As New Word.Application Dim docWord As Word.Document Dim rngWord As Word.Range Dim strDoc As String Dim numKey Dim numTable ' 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 _ 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) ' Reset Word range Set rngWord = docWord.Content ' Find second term rngWord.Find.Execute _ FindText:="Table Name:", MatchWildcards:=False, _ Wrap:=wdFindStop, Forward:=True ' Reset range to get number rngWord.Collapse wdCollapseEnd Do rngWord.MoveStart Unit:=wdCharacter, Count:=1 numTable = Trim(rngWord.Text) Loop Until Right(numTable, 1) < " " rngWord.MoveEnd Unit:=wdWord, Count:=1 ' Put number into variable numTable = Trim(rngWord.Text) MsgBox "The Primary Key is: " & numKey & "." MsgBox "The Table Name is: " & numTable & "." docWord.Close wdDoNotSaveChanges Set docWord = Nothing appWord.Quit Set appWord = Nothing End Sub -- pikapika13 ------------------------------------------------------------------------ pikapika13's Profile: http://www.excelforum.com/member.php...o&userid=10892 View this thread: http://www.excelforum.com/showthread...hreadid=570532 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SUMPRODUCT - Tweak | Excel Worksheet Functions | |||
Help with Dulpicate finding program.... | Excel Discussion (Misc queries) | |||
Array Help Tweak | Excel Worksheet Functions | |||
Code Tweak | Excel Programming | |||
Finding the Path to the Program Files Folder | Excel Programming |