Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Call Shell command in Outlook VBA to print an email with Bullzip's Printto.exe

Posted on 2013-02-07
10
Medium Priority
?
2,293 Views
Last Modified: 2013-02-08
I have VBA code that parses emails in a folder and for each one creates a text string of how I want to name a PDF file that is created by Bullzip's Printo.exe command.

I call a Sub with the command "  Call PrintEmailwithBullzip(strPutInFolder, Filename)"
That routine is:
Sub PrintEmailwithBullzip(ByVal strPutInFolder, ByVal Filename As String)

    Dim fso As New FileSystemObject
    Dim cff As New Bullzip.PDFPrinterSettings
    Dim cmd As String
    Dim isrunonce As String
    Dim ObjItem As Outlook.MailItem
    Set ObjItem = GetCurrentItem()
   
    cff.SetPrinterName ("Bullzip PDF Printer")

    With cff

        'Output = strPutInFolder & Filename & ".pdf"

        Rem -- Set the values
        .Init
        .SetValue "Output", strPutInFolder & Filename & ".pdf"
        .SetValue "ShowSettings", "always"
        .SetValue "ShowPDF", "no"
        .SetValue "WatermarkText", Now
        .SetValue "ShowProgress", "yes"
        .SetValue "ShowProgressFinished", "yes"
        .SetValue "SuppressErrors", "no"
        .SetValue "ConfirmOverwrite", "no"

        Rem -- Write settings to the runonce.ini
        .WriteSettings True
    End With
   
 'PrintFile = strPutInFolder & Filename & ".pdf"
   
      'cmd = """C:\Media\Bullzip\printto.exe"" Outlook.Application.ActiveExplorer.CurrentFolder.Item(ItemNmbr) ""Bullzip PDF Printer"""
    'cmd = """C:\Media\Bullzip\printto.exe"" & Outlook.Application.ActiveExplorer.CurrentFolder.Item(ItemNmbr)& ""Bullzip PDF Printer"""
    'cmd = "C:\Media\Bullzip\printto.exe " & Outlook.Application.ActiveExplorer.CurrentFolder.Item(ItemNmbr) & " ""Bullzip PDF Printer"""
    'cmd = "C:\Media\Bullzip\printto.exe " & "C:\Media\Bullzip\license.txt" & "Bullzip PDF Printer"
   
     'Call Shell("C:\Windows\system32\cmd.exe  " & cmd, 3)
     'Call Shell("C:\Windows\system32\cmd.exe  " & cmd, 1)
    'Call Shell("C:\Windows\system32\cmd.exe" /c & cmd, 0)

End Sub


I can't get the Call Shell( ) syntax correct.  Above are some of the combinations I've tried.  All seem to compile correctly and don't crash when I run them, but nothing is created.  
So I need someone familiar with Bullzip to check the setvalue statements. And a VBA mavin to give me the proper reference to the "then-current-mail-item" that the loop in the "get name" calling routine is "pointing to" which will print the PDF named as desired.

If you create the variables  strPutInFolder and  Filename (including ".pdf") in one sub, call it and pass them to this Sub, you can test.  I've left in all the tried and failed lines commented out.
0
Comment
Question by:Fritters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 38866502
Hi, Fritters.

The code below will run a command.

Sub RunExternalProgram(strCommand As String, bolWaitForReturn As Boolean)
    Dim objShell As Object
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run strCommand, , bolWaitForReturn
    Set objShell = Nothing
End Sub

Open in new window


I don't use Bullzip, so I can't tell you what the correct command line is.  Using one of the lines you listed above as a example, here's how you'd call it.

RunExternalProgram "C:\Media\Bullzip\printto.exe " & "C:\Media\Bullzip\license.txt" & "Bullzip PDF Printer"
0
 

Author Comment

by:Fritters
ID: 38866528
Compiling

RunExternalProgram "C:\Media\Bullzip\printto.exe " & "C:\Media\Bullzip\license.txt" & "Bullzip PDF Printer"  

returns a "Argument not optional" error.  Do I need to pass a second parameter to match the two in the subroutine?

so I tried to add a ,true as in

     RunExternalProgram ("C:\Media\Bullzip\printto.exe " & "C:\Media\Bullzip\license.txt" & "Bullzip PDF Printer", True)

and got a Compile error: Expected: =

BTW, I'm not trying to print "C:\Media\Bullzip\license.txt" or any file.  I'm trying to print an Outlook mailitem which I THINK is referenced as "Outlook.Application.ActiveExplorer.CurrentFolder.Item(ItemNmbr)" and is passed as part of the CMD string.

Not sure if that's the right way to reference the item, though I think it is.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 38867489
Yes, I forgot the second parameter.  The value you pass should probably be False (you don't need the macro to wait for the external process to finish).  The format of the command is

RunExternalProgram CommandToRun, True | False

As I said, I don't know anything about Bullzip, so I don't know what command to run.  From what you wrote ("I want to name a PDF file that is created by Bullzip's Printo.exe command.") it sounded like you need to run the Bullzip program and pass it something.  If you just need to print the Outlook message, then

    ObjItem.PrintOut

will do that.  You don't need to run an external program at all.  If instead you do need to run Bullzip, then you'll have to determine the command to run and pass it RunExternalProgram.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:Fritters
ID: 38868060
ObjItem.PrintOut may print the email item, but the Filename and Path information would be completely ignored.  Not a solution.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 38868443
I downloaded and installed a copy of Bullzip so I could see for myself how it works.  I then put together a solution that prints a message from Outlook.  Here's that code.  To use this, call PrintMsgWithBZ and pass it the message to print, the path to the folder you want the resulting PDF to appear in, and the name you want to give the PDF file.

Sub PrintMsgWithBZ(olkMsg As Outlook.MailItem, strFolder As String, strFilename As String)
    Dim objBZSettings As New Bullzip.PDFPrinterSettings
    With objBZSettings
        .SetPrinterName "Bullzip PDF Printer"
        .Init
        .SetValue "Output", strFolder & "\" & strFilename & ".pdf"
        .SetValue "ShowSettings", "never"
        .SetValue "ShowSaveAs", "never"
        .SetValue "ShowPDF", "no"
        .SetValue "WatermarkText", Now
        .SetValue "ShowProgress", "yes"
        .SetValue "ShowProgressFinished", "yes"
        .SetValue "SuppressErrors", "no"
        .SetValue "ConfirmOverwrite", "no"
        .WriteSettings True
    End With
    olkMsg.PrintOut
    Set objBZSettings = Nothing
End Sub

Open in new window

0
 

Author Comment

by:Fritters
ID: 38868743
Here's the line in my calling subroutine:
Call PrintMsgWithBZ(Outlook.Application.ActiveExplorer.CurrentFolder.Item(ItemNmbr), strPutInFolder, strFilename)

I'm assuming that the parameter names being passed don't have to be exactly the same as the parameters in your subroutine.

Long and short, not only aren't any PDF's created ( manually set the default printer to the Bullzip PDF Printer), a "runonce.ini" file is not created (where it didn't exist as it's supposed to) and doesn't get edited with the .setValue's as it used to in my non-working code.
0
 

Author Comment

by:Fritters
ID: 38868756
olkMsg.PrintOut?  Ahh, the first parameter.  I see.
0
 

Author Comment

by:Fritters
ID: 38868818
Found an "error".  My calling Sub already put a "\" on the strFolder.  You added a second one in your routine.  Testing again.  Wait.
0
 

Author Comment

by:Fritters
ID: 38869649
Well, I guess I have to give credit for the solution.  I had been attempting to use the printto.exe program to cause the printout and that was the source of the problem for me.  I had a very similar routine to your code already that worked when printing an individual email item but when realized that such code or yours could be a routine called from a loop, that put me on the right track.
However I realized that my code in the calling routine (not posted here) was not setting the default printer to Bullzip which I need to happen for your or my code.  I had been using some code I found online.  Must have messed it up.  But, in any case, when I set the default printer to manually, your solution works.  so, I'll accept it.
0
 

Author Closing Comment

by:Fritters
ID: 38869654
See my post for explanation.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question