Results 1 to 2 of 2

Thread: printing word document

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    I have a word document I would like to print when pressing a command button on my app.
    How does one do this I ask with tears in my eyes.
    Thanks.
    dan.

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    Printing Word Document

    Hi Dan,
    Here is the solution for your problem.Follow the steps:

    1. In the VB click the Project>References>Microsoft Word Object8.0(don't worry about the version.Take the version you have).
    2. After giving reference to word object,write the following code in the button's click event.

    'Declare in the general declaration section
    Dim wWord As Word.Application

    Private Sub Command1_Click()
    Set wWord = New Word.Application

    'Use this code if you want to open any document.In this i saved "hi.doc" on my desktop
    Documents.Open "c:\windows\desktop\hi.doc"
    ActiveDocument.PrintOut Range:=wdPrintCurrentPage

    'This code prints the current page of the active document.
    ActiveDocument.PrintOut Range:=wdPrintCurrentPage

    'This code prints the first five pages of the document in the active window.
    ActiveWindow.PrintOut Range:=wdPrintFromTo, From:="1", To:="5"

    'This will print all the documents in current folder.
    adoc = Dir("*.DOC")
    While adoc <> ""
    Application.PrintOut FileName:=adoc
    adoc = Dir()
    Wend

    End Sub

    Hope this will help you...

    Good Luck

    Regards
    Anil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width