|
-
Nov 13th, 2012, 04:17 AM
#19
Thread Starter
Junior Member
Re: Outlook VBA script to save file with subject as filename
No messagebox and no saving the attachement even when I changed the line you said. However, when I looked more closely at the VBA script in alt+f11 I noticed that the MsgBox strName didn't seem to be a part of the code... It had some kind of line separating it from the rest of the code, and when I moved it under the line "Sub SaveAllAttachments(objitem As MailItem)" and sent myself a mail with attachement I get this error:
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
Duplicate declaration in current scope
---------------------------
OK Help
---------------------------
And it highlights this line in yellow:
Sub SaveAllAttachments(objitem As MailItem)
My current code looks like this:
Sub SaveAllAttachments(objitem As MailItem)
MsgBox strName
Dim objAttachments As Outlook.Attachments
Dim strName, strLocation As String
Dim dblCount, dblLoop As Double
strLocation = "K:\Ny mappe struktur\Servicemarked\Volkswagen og Audi verksted\Gjennomganger - Teksteark\Jack\"
On Error GoTo ExitSub
If objitem.Class = olMail Then
Set objAttachments = objitem.Attachments
dblCount = objAttachments.Count
If dblCount <= 0 Then
End If
For dblLoop = 1 To dblCount
strName = strLocation & Replace(Mid(objitem.Subject, 13, Len(fn) - 25), "/", " ") & ".pdf"
MsgBox strName ' just to see it the path\filename lloks like it is correct
objAttachments.Item(dblLoop).SaveAsFile strName
Next dblLoop
'objitem.Delete
End If
100
ExitSub:
Set objAttachments = Nothing
Set objOutlook = Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|