Re: How to print from VB

Tech-Archive recommends: Fix windows errors by optimizing your registry



Whoops! Forgot the declarations.

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 = 0

--
Mike
Microsoft MVP Visual Basic



"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:OOCNM$4NFHA.2748@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Jenny Smith" <j_a_smith@xxxxxxxxxxx> wrote in message
> news:inl3e.7447$V62.3849@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > Hello,
> >
> > Hope anyone can help me with this problem. I need to be able to allow
> user
> > to print any Windows App files from my VB program, such as .doc, .pdf,
> .txt,
> > .wri ....
>
>
> If all the file types you want to print are associated with an
application,
> you can use this:
>
> Dim sFileToPrint As String
> Dim lRet As Long
>
> 'Path is hard-coded for example purposes only
> sFileToPrint = "C:\MyApp\MyFile.doc"
>
> lRet = ShellExecute(Me.hwnd, "print", sFileToPrint, vbNullString,
> vbNullString, SW_HIDE)
> If lRet < 33 Then
> MsgBox "Unable to print"
> End If
>
> You might want to use a Select Case on the return value and provide better
> information as to why it couldn't print. Look up ShellExecute in the
> Platform SDK for the meanings of all its return values. Also note that
just
> because SW_HIDE was specified, the app *may* still briefly appear.
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>


.



Relevant Pages

  • Re: list
    ... Surprised noone mentioned ShellExecute. ... Private Declare Function GetDesktopWindow Lib "user32.dll" As Long ... ByVal lpFile As String, _ ... Dim hWnd As Long, iRet As Long ...
    (microsoft.public.vb.controls)
  • RE: Open PDF located in excel with macro
    ... Private Declare Function ShellExecute Lib "shell32.dll" _ ... ByVal lpFile As String, ByVal lpParameters As String, _ ... ShellExecute 0, "open", strFile, vbNullString, vbNullString, 9 ... When I click this button I would like the User guide to open. ...
    (microsoft.public.excel.programming)
  • Re: Using Shell method to "Print" pdf and then pausing until pdf c
    ... ShellExecute to launch a PDF document and then I need to call ... Private cncurrent As ADODB.Connection, strTempFile As String ... Private Const SW_HIDE = 0 ...
    (microsoft.public.access.modulesdaovba)
  • Re: install msxml.msi - problem
    ... Private Declare Function ShellExecute Lib "shell32.dll" Alias ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal ... "Bala" wrote in message ...
    (microsoft.public.vb.general.discussion)
  • Re: IE Shell
    ... Private Declare Function ShellExecute Lib "shell32.dll" Alias ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal ...
    (microsoft.public.vb.general.discussion)