Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
fetch data from excel page | Excel Programming | |||
Use of Indirect function to fetch data from another Excel file | Excel Worksheet Functions | |||
How to fetch rows of data across sheets dynamically | Excel Programming | |||
Open a specific Word document from an Excel Macro | Excel Programming | |||
Open a password protected excel workbook from second workbook to fetch data using dynamic connection | Excel Programming |