Hi,
How can i access a word document and "put" some data in that document ? print the doc?
thanks
Printable View
Hi,
How can i access a word document and "put" some data in that document ? print the doc?
thanks
Hi,
Have you try thru VBA?
Opening a word document in Visual Basic :
Once you have opened the document you can perform ANY VBA function on the document using the oWord object.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
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.
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
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.
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.Code:' In VBA
ActiveDocument.Select
Selection.TypeText "Fred Was Here"
' In VB
oWord.Application.Documents(1).Select
oWord.Application.Selection.TypeTExt "Fred Was Here"
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.
GenX,
THANX