ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open Word and fetch specific data (https://www.excelbanter.com/excel-programming/368709-open-word-fetch-specific-data.html)

pikapika13[_18_]

Open Word and fetch specific data
 

Darn, did everyone leave for the weekend?
I need a macro that will open up a word document, look for two ke
words: "Primary Key:" and return the number that follows this specifi
word, go down the document and look for another key word: "Table Name:
and return it's number as well.
I hope this is a simple request, and thanks much in advance.:

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


Ed

Open Word and fetch specific data
 
Hi. This worked for me in Excel and Word XP. Better hurry with any
questions, though, 'cuz my weekend's about to start! <g
--
Ed
Chief Chef,
Kludge Code Cafe
"Spaghetti Is Our Specialty!"
'

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" wrote
in message ...

Darn, did everyone leave for the weekend?
I need a macro that will open up a word document, look for two key
words: "Primary Key:" and return the number that follows this specific
word, go down the document and look for another key word: "Table Name:"
and return it's number as well.
I hope this is a simple request, and thanks much in advance.:)


--
pikapika13
------------------------------------------------------------------------
pikapika13's Profile:
http://www.excelforum.com/member.php...o&userid=10892
View this thread: http://www.excelforum.com/showthread...hreadid=566182




pikapika13[_19_]

Open Word and fetch specific data
 

ha! my weekend just started too. I'll check it out after a little R and
R. I appreciate the reply. Have a good one.


--
pikapika13
------------------------------------------------------------------------
pikapika13's Profile: http://www.excelforum.com/member.php...o&userid=10892
View this thread: http://www.excelforum.com/showthread...hreadid=566182


pikapika13[_20_]

Open Word and fetch specific data
 

Ed,

I didn't want this post to go by without a thanks! It work
beautifully

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


Ed

Open Word and fetch specific data
 
Glad to help. It feels good to be able to help someone else for a change.
I know I've received more than my fair share from the good people here.

Ed

"pikapika13" wrote
in message ...

Ed,

I didn't want this post to go by without a thanks! It works
beautifully.


--
pikapika13
------------------------------------------------------------------------
pikapika13's Profile:
http://www.excelforum.com/member.php...o&userid=10892
View this thread: http://www.excelforum.com/showthread...hreadid=566182





All times are GMT +1. The time now is 01:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com