Saya menemukan makro VBA yang mencetak lampiran Outlook secara otomatis. Aturan memicu makro.
Tetapi makro perlu referensi Microsoft Scripting Runtime
untuk bekerja. Saya menyimpan kode di ThisOutlookSession dan berfungsi dengan baik ketika saya mereferensikan perpustakaan melalui Tools »Referensi.
Tetapi referensi perlu ditambahkan setiap kali program dibuka. Makro ada di sana setelah startup, tetapi referensi tidak. Saya ingin makro berjalan terus menerus tanpa perlu klik tambahan apa pun saat startup sistem.
Sub LSPrint(Item As Outlook.MailItem)
On Error GoTo OError
'detect Temp
Dim oFS As FileSystemObject
Dim sTempFolder As String
Set oFS = New FileSystemObject
'Temporary Folder Path
sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)
'creates a special temp folder
cTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
MkDir (cTmpFld)
'save & print
Dim oAtt As Attachment
For Each oAtt In Item.Attachments
FileName = oAtt.FileName
FullFile = cTmpFld & "\" & FileName
'save attachment
oAtt.SaveAsFile (FullFile)
'prints attachment
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(0)
Set objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")
Next oAtt
'Cleanup
If Not oFS Is Nothing Then Set oFS = Nothing
If Not objFolder Is Nothing Then Set objFolder = Nothing
If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
If Not objShell Is Nothing Then Set objShell = Nothing
OError:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
End If
Exit Sub
End Sub