how to print a html file from my vb app.?
Printable View
how to print a html file from my vb app.?
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:
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.VB Code:
' Add the following line at the beginning of a form: 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 ' and assign this to the action of a button e.g. click: Private Sub Command1_Click() Dim BeginPage, EndPage, NumCopies, Orientation, i ' set "Cancel" to "True" CommonDialog1.CancelError = True On Error GoTo ErrHandler ' show printing-dialogue CommonDialog1.ShowPrinter ' get user-values BeginPage = CommonDialog1.FromPage EndPage = CommonDialog1.ToPage NumCopies = CommonDialog1.Copies Orientation = CommonDialog1.Orientation For i = 1 To NumCopies ' add here the information of the file to be printed: ' e.g.: Dim PrintIt As Long PrintIt = ShellExecute(Me.hwnd, "PRINT", App.Path + "\MyDocument.HTML", "", "", -1) Next Exit Sub ErrHandler: ' user aborted printing Exit Sub End Sub