automatically print attachments

Status
Not open for further replies.

crashbrown98

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hello,

I have a script to print attachments automatically and itworks well however when it prints it does it as actual size instead offit. Is there a way to adjust the scriptto do it as fit instead of actual size for .pdf

Here is the code used:

Sub LSPrint(Item As Outlook.MailItem)
On Error GoToOError
'detect Temp
Dim oFS AsFileSystemObject
Dim sTempFolder AsString

Set oFS = NewFileSystemObject
'Temporary FolderPath
sTempFolder =oFS.GetSpecialFolder(TemporaryFolder)

'creates a specialtemp folder
cTmpFld =sTempFolder & "\OETMP" & Format(Now,"yyyymmddhhmmss")
MkDir (cTmpFld)
'save & print
Dim oAtt AsAttachment
For Each oAtt In Item.Attachments
FileName =oAtt.FileName
FullFile =cTmpFld & "\" & FileName

'save attachment
oAtt.SaveAsFile(FullFile)

'printsattachment
Set objShell =CreateObject("Shell.Application")
Set objFolder =objShell.NameSpace(0)
SetobjFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")

Next oAtt

'Cleanup
If Not oFS IsNothing Then Set oFS = Nothing
If Not objFolderIs Nothing Then Set objFolder = Nothing
If NotobjFolderItem Is Nothing Then Set objFolderItem = Nothing
If Not objShell IsNothing Then Set objShell = Nothing

OError:
If Err <> 0Then
MsgBoxErr.Number & " - " & Err.Description
Err.Clear
End If
Exit Sub

End Sub
 

crashbrown98

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Generally speaking, no, because the printer commands are not exposed in the object model. If the pdf application supports this open via a command line, you may be able to do it.

when it comes to macros i got as much knowledge as a 3 yr old. i can understand them to a point but after that im clueless. so there is no way to tell adobe how to print it unless i would run a sub macro for adobe?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
According to the Acrobat SDK, it looks like you can use OLE -

Function PrintPages(nFirstPage As Long, nLastPage As Long, nPSLevel As Long, bBinaryOk As Long, bShrinkToFit As Long) As Boolean

I found this sample and it works to print from outlook, but I'm not sure of the correct setting for shrink to fit. Oh, and you need to set a reference to Acrobat in Tools, References. And it only works with Acrobat, not reader.

Code:
Public Sub AcrobatPrint() 
 
Dim FileName As String ' this is the filename variable, i replaced it with a hardcoded filename for testing 
 
Dim PrintMode As String
    Dim AcroExchApp As Acrobat.CAcroApp
    Dim AcroExchAVDoc As Acrobat.CAcroAVDoc
    Dim AcroExchPDDoc As Acrobat.CAcroPDDoc
    Dim num As Integer
    Set AcroExchApp = CreateObject("AcroExch.App")
    Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
    ' Open the [Filename] pdf file
    ' use FileName variable instead of hardcoded file name
    AcroExchAVDoc.Open "C:\Users\Diane\Downloads\a-pdf.pdf", ""
    'Get the PDDoc associated with the open AVDoc
    Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
    'Get the number of pages for this pdf [and subtract one as zero based]
    num = AcroExchPDDoc.GetNumPages - 1
    If PrintMode = "All" Then
         'Print Entire Document
          Call AcroExchAVDoc.PrintPages(0, num, 2, 1, 1)
    Else
          If num = 0 Then
              'Print entire document (one page)
              ' Last value is shrinktofit
               Call AcroExchAVDoc.PrintPages(0, num, 2, 1, 1)
          Else
              'Print first two pages
               Call AcroExchAVDoc.PrintPages(0, 1, 1, 1, 1)
          End If
    End If
    AcroExchApp.Exit
    AcroExchAVDoc.Close (True)
    AcroExchPDDoc.Close 
 
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
As an FYI, i added a working sample to my print attachments page at Use Acrobat's Printer Options.

It should be fairly easy to tweak your code to use the select case statement from my code to identify pdf files and send them to the print pdf macro. Or use an If statement to send them to the pdf code.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
I Print Automatically Attachments Outlook VBA and Custom Forms 3
5 Automatically print email attachments Using Outlook 7
J Automatically Print PDF When They Are Received Using Outlook 4
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
W Automatically open attachments without automatically printing them Using Outlook 0
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
M Outlook 2016 Rules Not Working Automatically Using Outlook 5
Diane Poremsky Automatically create a task when sending a message New Slipstick.com Articles 0
D Is it possible to automatically send an email when it is moved to a folder? Exchange Server Administration 1
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
Diane Poremsky Create Appointment From Email Automatically New Slipstick.com Articles 0
Cameron Piper Automatically update custom forms across multiple computers Outlook VBA and Custom Forms 1
T Automatically open link in email received Outlook VBA and Custom Forms 33
N Automatically file email messages Using Outlook 2
J Automatically Move Old Items from a Shared Mailbox to a .PST on a Network Drive Outlook VBA and Custom Forms 1
M Change default "automatically test account settings when Next is clicked" Using Outlook 1
D Automatically file message and reply to folder. Using Outlook 1
A Code to automatically delete message after sending Outlook VBA and Custom Forms 6
Diane Poremsky Automatically Create Contacts From Messages New Slipstick.com Articles 1
T Outlook 2010 emails do not refresh automatically Exchange Server Administration 1
L Save Mail Message to new folder created automatically Outlook VBA and Custom Forms 1
G Hae Rules NOT perform automatically? Using Outlook 1
F Automatically close email after selecting mark unread Using Outlook 1
nathandavies How to save emails to a specific folder on a network automatically using a macro Outlook VBA and Custom Forms 14
T Default inbox not automatically sending/receiving Using Outlook 1
Angger Microsoft Outlook 2010 Automatically Restarting Using Outlook 2
N Outlook Shared appointments automatically to Private Calendar Using Outlook 1

Similar threads

Top