Discussion Locked

Help me to Print Word document from VB6

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i want to print microsoft word document from my program in VB6 ,
I use wordbasic's command like :
wordbasic.fileopen .etc
i can open some files but not all
I can't open the word file have option button (i need to make form in word)
but when i insert option button in the the word doc. the VB can't open the file
what can i to do?

5 replies

by dragon emperor

You will also need to add a reference to the word object library.

Dim objMSWord As Word.Application
Dim objMSWordDoc As Word.Document

If Dir$(strFilePath) <> "" Then
Set objMSWord = New Word.Application

objMSWord.Visible = True
Set objMSWordDoc = _ objMSWord.Documents.Open(strFilePath, True)
objMSWordDoc.Activate
objMSWordDoc.PrintOut False
objMSWordDoc.Close _ wdPromptToSaveChanges, wdPromptUser
Set objMSWordDoc = Nothing
objMSWord.Quit
SetobjMSWord = Nothing
End If

by rrv

dim wdApp as New Word.Application
dim wdDoc as Word.Document
dim wdRng as Word.Range
dim wdTbl as Word.Table
Set wdApp = CreateObject("Word.Application")
With wdApp
.Options.Pagination = True

.Documents.Add (App.Path & "\DOC Prints.doc")Set wdDoc = wdApp.ActiveDocument
Set wdRng = wdApp.ActiveDocument.Range(0, 0)
wdRng.Font.Italic = False
wdRng.Font.Size = 10
Set wdTbl = wdDoc.Tables.Add(wdRng, 5,2)
end with
Like this you can go on doing. Easy way to find all the commands etc is very easy. in word start recording a new macro. thne start doing what you want and stop the macro. then edit the macro. you have all the VB code in it for what you want. just copy that into your VB editor and that is it.
for more details check msdn help or email to me.
rrv@hotvoice.com
All the best.

This discussion is closed to new replies.