Results 1 to 2 of 2

Thread: Print html file

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    119

    Print html file

    how to print a html file from my vb app.?

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    First of all you have to add a component called COMDLG32.OCX. After adding this component, position one on your form and name it "CommonDialog1" and copy and paste the following code:

    VB Code:
    1. ' Add the following line at the beginning of a form:
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    3.  
    4. ' and assign this to the action of a button e.g. click:
    5. Private Sub Command1_Click()
    6.     Dim BeginPage, EndPage, NumCopies, Orientation, i
    7.    ' set "Cancel" to "True"
    8.    CommonDialog1.CancelError = True
    9.    On Error GoTo ErrHandler
    10.    ' show printing-dialogue
    11.    CommonDialog1.ShowPrinter
    12.    ' get user-values
    13.    BeginPage = CommonDialog1.FromPage
    14.    EndPage = CommonDialog1.ToPage
    15.    NumCopies = CommonDialog1.Copies
    16.    Orientation = CommonDialog1.Orientation
    17.    For i = 1 To NumCopies
    18.    ' add here the information of the file to be printed:
    19. '  e.g.:
    20.         Dim PrintIt As Long
    21.         PrintIt = ShellExecute(Me.hwnd, "PRINT", App.Path + "\MyDocument.HTML", "", "", -1)
    22.    Next
    23.    Exit Sub
    24. ErrHandler:
    25.    ' user aborted printing
    26.    Exit Sub
    27. End Sub
    Its the ShellExecute statement that does the printing. It launches whatever application is associated with HTML files, opens the MyDocument.HTML in it, and then Prints it.

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