Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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
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
fetch data from excel page Mark[_64_] Excel Programming 1 May 21st 06 04:09 PM
Use of Indirect function to fetch data from another Excel file Boon8888 Excel Worksheet Functions 1 January 20th 06 07:46 PM
How to fetch rows of data across sheets dynamically knowledgehunter Excel Programming 2 December 4th 05 04:09 PM
Open a specific Word document from an Excel Macro Canoeist Excel Programming 3 March 22nd 05 06:35 AM
Open a password protected excel workbook from second workbook to fetch data using dynamic connection kaustav choudhury Excel Programming 2 April 3rd 04 06:18 AM


All times are GMT +1. The time now is 09:14 PM.

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"