Print Word Documents And MS Projects

TheWizardofInt

Well-known member
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I need to print Word Documents and MS Projects, without showing them. These are standard templates that just need to be printed and mailed to clients

Code:
   Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal _
        hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, _
        ByVal nShowCmd As Integer) As Integer

    Public Function PrintFromShell(ByVal sFile As String) As Integer
        use the shell command to print 
        Dim NewProcess As Process = New Process
        Dim hHandle As System.IntPtr
        Dim i As Integer
        Dim proc As Process

        proc.GetProcesses(Environment.MachineName)
        For Each proc In proc.GetProcesses
            If proc.ProcessName = Application.ProductName Then
                hHandle = proc.Handle
               
                Exit For
            End If
        Next

        i = ShellExecute(hHandle, "print", _
            sFile, vbNullString, sGlobTemplates, 0)

        Return i
    End Function

This words, but it shows the document as it prints it. I tried setting constant SW_Hide=0 but of course got the same result

Any idea what the new SW_Hide value in .Net should be?
 
PlausiblyDamp said:
If you are using .Net why dont you use the System.Diagnostics.Process class? It will be much easier than calling into ShellExecute.

It wouldnt print at all

I am assuming process(sFile, "Print") - probably got that wrong
 
Code:
Dim pi As New System.Diagnostics.ProcessStartInfo
pi.Verb = "Print"
pi.FileName = "c:\autoexec.bat"

Dim p As New System.Diagnostics.Process
p.StartInfo = pi
pi.WindowStyle = ProcessWindowStyle.Hidden
p.Start()
 
Back
Top