Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SUMPRODUCT - Tweak Sam via OfficeKB.com Excel Worksheet Functions 2 September 6th 07 04:12 PM
Help with Dulpicate finding program.... Patti Excel Discussion (Misc queries) 1 February 5th 07 08:57 PM
Array Help Tweak Luke Excel Worksheet Functions 13 November 22nd 06 10:29 AM
Code Tweak bodhisatvaofboogie Excel Programming 1 July 21st 06 04:37 PM
Finding the Path to the Program Files Folder JGS[_2_] Excel Programming 2 December 12th 05 09:16 AM


All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"