-
Outlook 2007 vba
I am a learner - so apologies if my question is simple.
I am using a macro that looks in the body of an email for specific data to use later in a file name.
Where I have an explicit declaration as in Example1, no problem, but if I manipulate the sbody variable, I get an error message: 'Outlook cannot complete the save due to a file permission error'.
Can anyone tell me what I am doing wrong?
Example 1
sbody = MyMail.Body
LPos = InStr(sbody, "Type of Check:")
If Mid(sbody, LPos + 15, 9) = "New Check" Then
CheckType = "NewChecks"
Else
CheckType = "Rechecks"
End If
Save_Path = Save_Path & CheckType & ".txt"
msg.SaveAs Save_Path, olTXT ( Works OK)
Example 2
sbody = MyMail.Body
LPos = InStr(sbody, "Policy Reference:")
XPos = InStr(sbody, "Talbot DMS Location:")
CheckType = "Check_" & Mid(sbody, LPos + 18, (XPos - 1) - (LPos + 18))
Save_Path = Save_Path & CheckType & ".txt"
msg.SaveAs Save_Path1, olTXT (Fails)