Programmering af lille print macro fra outlook
Hejsa,Jeg forsøger at få outlook til at printe nogle vedhæftninger i en specifik rækkefølge. Hertil har jeg fundet en stump kode på nettet. Alle vedhæftninger er i PDF og kan sagtens printes korrekt ud i den rækkefølge de er gemt i mailen, hvis jeg kører debug mode med breakpoints. Men så snart jeg bare sætter den til at køre automatisk, så printer den enten kun det første dokument ellers printer den ud i helt random rækkefølge. Grunden til at jeg forsøger mig med en macro er at outlooks normale printfunktion også bare printer i random rækkefølge.
Dette er så langt jeg er nået med min kode so far.
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub PrintAttachment()
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim strFile As String
'Set destination folder
myOrt = "h:\"
On Error Resume Next
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For Each myItem In myOlSel
Set myAttachments = myItem.Attachments
If myAttachments.Count > 0 Then
For i = 1 To myAttachments.Count
myAttachments(i).SaveAsFile myOrt & myAttachments(i).DisplayName
strFile = myOrt & myAttachments(i).DisplayName
If strFile <> fesdpacket.XML Then
ShellExecute 0&, "print", strFile, 0&, 0&, 0&
Sleep 5000
End If
Next i
myItem.Save
End If
Next
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
killString = "taskkill /F /IM AcroRd32.exe"
Call Shell(killString, vbHide)
ShellExecute 0&, "del", strFile, 0&, 0&, 0&
End Sub
