Log in

View Full Version : Macro working on one pc, not the other.



ArnoD1995
05-02-2016, 12:43 AM
Best all,


Well, i've created the following macro ('created' > mostly copied from others), but ran into a problem which seems very strange to me.







Sub Print_bijlagen()
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer


If MsgBox("Weet u zeker dat u alle bijlagen van mails uit de geselecteerde map wilt afdrukken? (PDF only!)", vbOKCancel, "Buitelaar Houtconstructies B.V.") = vbOK Then

Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.folders.Item("Printmap")


For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Temp\" & Atmt.FileName & i
Atmt.SaveAsFile FileName
i = i + 1
Shell """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"" /h /p """ + FileName + """", vbHide
Next



Next


Set Inbox = Nothing



Else
MsgBox "Afdrukken geanuleerd"



End If


End Sub


(Texts are in dutch)


What it does is printing all attachments (pdf only) from the mails in a specific folder, in this instance it's the folder called "PRINTMAP".


It works great on my pc, so i tried installing it on my colleagues' pc, but unfortanately it's not working. It goes into error on the following line:



Atmt.SaveAsFile FileName


I already adapted the path to the adobe reader, but it won't work (didn't expect that to fix the error either, as it is 'later' in the macro..)


I hope you guys can help me finding the problem of the not working macro on my colleagues' pc.

Both pc's use Outlook 2013, win 7 64-bit, they are completely identical.




Best regards,
Arno Dekkers

gmayor
05-02-2016, 02:09 AM
Does your colleague's PC have a folder C:\Temp ?

The Windows Temp folder can be accessed with Environ("Temp")

You have not declared an initial value for i so FileName = "C:\Temp\" & Atmt.FileName & i doesn't make any sense for the first attachment, and in any case that would put the count after the extension which produces an invalid PDF filename.

There are Functions at http://www.gmayor.com/useful_vba_functions.htm which will handle existing filenames, should you require it, and you should introduce a trap to ensure only PDF format attachment files are processed.