Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Run a Word macro/vba function using data from the document?

Status
Not open for further replies.

cobas

Programmer
Feb 4, 2002
21
GB
I have several word documents that ALWAYS have the document number on the first line and the document type on the second line. How do I either set these up as fields on the document so that they can be read by vba code and output to another application? OR how do I read the first 2 lines of the document in vba / macro to send to another application?

The other app is possibily a document management app.

Thanks In Advance
 
[tt]
Since moving from VBA to ASP (Web Development) I don't have too much time to actually work in VBA anymore, but over the years I've collected pieces here and there that were very helpful at one point and I found this piece that might either help you or get you going in the right direction:

Have the VBA gurus trouble shoot it if you need further assistance...

'Place the code below into the standard module
Sub WordImport()
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim rngAct As Word.Range
Set appWord = CreateObject("Word.Application")
Set docWord = appWord.Documents.Open("c:\YouFolderName\YourFileName.doc")
Set rngAct = docWord.Paragraphs(1).Range
rngAct.Copy
Application.DisplayAlerts = False
ActiveSheet.Paste
Application.DisplayAlerts = True
appWord.Quit
Set docWord = Nothing
Set appWord = Nothing
End Sub

good luck...




[sup]
[ul][li]What do all these errors in ASP really mean? .... [/li] [li]What are the many ways to send emails with ASP? .... [/li][li]Where can I learn ASP? .... [/li][/ul]
[/sup]
 
Tony

Thanks for the reply, I'll give it try later today and let you know how I get on.

 
Tony

Was shown another method before I tried your code, ended up using form fields calling a function to build I command line string with the values from the document.

Thanks for the reply to the original posting.

Colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top