Solved

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

Posted on 2013-02-07
10
2,212 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

756 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