|
-
Apr 12th, 2000, 12:26 PM
#1
Thread Starter
Addicted Member
Hi,
How can i access a word document and "put" some data in that document ? print the doc?
thanks
-
Apr 12th, 2000, 12:30 PM
#2
New Member
Hi,
Have you try thru VBA?
-
Apr 12th, 2000, 12:32 PM
#3
Hyperactive Member
Opening a word document in Visual Basic :
Code:
Dim oWord as Object
Dim sWordFile as String
sWordFile = "C:\Folder\Document.doc"
Set oWord = GetObject(sWordFile, "Word.Document")
'------- Its now open ---------------
Msgbox oWord.Application.Documents(1).Name
.
.
.
'------- Now close it and automatically save it
oWord.Application Quit 0
Set oWord = Nothing
Once you have opened the document you can perform ANY VBA function on the document using the oWord object.
I would suggest learning how do to everything you wanted from VBA first (Load Word, Press Alt-F11 to get to the VB Editor and start learning) and then migrate it to word.
There are heaps of examples in the VB Word Help files.
-
Apr 12th, 2000, 12:43 PM
#4
Thread Starter
Addicted Member
GenX
Thanks for the quick reply, but i need to read data and put the data in the document (the header is already there).
is it good to inplement by VBA or VB?
Thanks
-
Apr 12th, 2000, 12:52 PM
#5
Hyperactive Member
This might get a bit confusing but I will try and explain.
VBA is the language used to run Macros in Word.
That means that if you use VBA you will be writing Macros that exist in either the Normal.dot or another template that you have as an add-in.
If you want to do this from VB you actually USE the VBA calls to objects and attributes.
So like I said in my previous post.... FIRST learn how to use VBA to actually do what you want and then when you get to VB you replace the reference to objects with the object model I gave you instead of just using VBA.
Code:
' In VBA
ActiveDocument.Select
Selection.TypeText "Fred Was Here"
' In VB
oWord.Application.Documents(1).Select
oWord.Application.Selection.TypeTExt "Fred Was Here"
Now don't quote me Word for Word on the code... I only pulled that off the top of my head to give you an idea of how things work... you will need to do the proper syntax yourself.
But the bottom line is that using Word through Visual Basic is a matter of using the Word objects which is exactly what you do in VBA but in slightly different ways.
-
Apr 12th, 2000, 04:23 PM
#6
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|