Hi all,
Can any body gice me a idea how to print a document using Word object?
Regards
Sachien
Printable View
Hi all,
Can any body gice me a idea how to print a document using Word object?
Regards
Sachien
Here is how to do this from VB.
:thumb:VB Code:
Option Explicit 'Add a Reference to MS Word xx.0 Object Library Private moApp As Word.Application Private Sub Command1_Click() Dim oDoc As Word.Document Set oDoc = moApp.Documents.Open("C:\Test.doc") oDoc.PrintOut True oDoc.Close False Set oDoc = Nothing End Sub Private Sub Form_Load() Set moApp = New Word.Application moApp.Visible = False moApp.WindowState = wdWindowStateMinimize End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If TypeName(moApp) <> "Nothing" Then moApp.Quit False End If Set moApp = Nothing End Sub
Here is how to do it without using the WOM.
VB Code:
Option Explicit 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 Private Const SW_HIDE As Long = 0 Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMINIMIZED As Long = 2 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Sub Command1_Click() ShellExecute Me.hwnd, "Print", "C:\Test.doc", vbnulllstring, "C:\", SW_HIDE End Sub
Hey Thanks Buddy
This Was cool ;)
No prob. :thumb:
Ps, to Resolve your thread you need to edit your First post so it will show at the forum level as resolved ;)