When I initially coded the excel sheet and vba for those sheets, I was working in Excel 2007. Work has now decided to "update" the computers, but they have backdated our office suite from 2007 to 2003. This has caused a bit of an annoyance for some of the macros and things that I had coded in 2007
I have a command button that checks the emails in Outlook over the past 6 days to find a specific email. If it can find it, it tries to save the attachement. If its unable to find it, it says that it cant find it and exits the sub without doing anything.
I have pretty much the same code in 2 different workbooks. One workbook works ok, and the other doesn't. When I run the one that doesn't work it comes up with the following error:
This is the code that says I dont have permission to save the file. The part the gets highlighted in the debugger is the "SaveAsFile" part.
Here is the code from the workbook that works properly, and saves the file without any errors.
Any help with this will be greatly appreciated. I've got no idea what could be wrong because as you can see, the code is pretty much the same in both workbooks.
I have a command button that checks the emails in Outlook over the past 6 days to find a specific email. If it can find it, it tries to save the attachement. If its unable to find it, it says that it cant find it and exits the sub without doing anything.
I have pretty much the same code in 2 different workbooks. One workbook works ok, and the other doesn't. When I run the one that doesn't work it comes up with the following error:
Run-time error '-2147024891 (80070005)':
Cannot save the attachment. You don't have appropriate permission to perform this operation.
This is the code that says I dont have permission to save the file. The part the gets highlighted in the debugger is the "SaveAsFile" part.
Code:
i = 0
Do While i < 7
For Each msgMail In mpiFolder.Items
If msgMail.Class = 43 Then
If msgMail.Subject Like "*" & "Store" & "*" & "Shipment Notification" & "*" & Format(Date - i, "DD/MM/YYYY") & "*" Then
todaysDate = Format(Date - i + 1, "DD/MM/YYYY")
strSubject = msgMail.Subject
msgMail.Attachments.Item(1).SaveAsFile Trim(strAQSPath & "\DELIVERY.xls")
FileSaved = True
Exit For
End If
End If
Next
If Range("A65536").End(xlUp).Value Like "*" & Format(Date - i + 1, "DD/MM/YYYY") & "*" Then
MsgBox ("This delivery has already been added to your stock.")
FileSaved = True
AlreadyAdded = True
i = 7
End If
i = i + 1
Loop
Here is the code from the workbook that works properly, and saves the file without any errors.
Code:
For Each msgMail In mpiFolder.Items
If msgMail.Class = 43 Then
If msgMail.Subject Like "*" & "Store" & "*" & "Serial Information" & "*" & Format(Date, "DD/MM/YYYY") & "*" Then
strSubject = msgMail.Subject
msgMail.Attachments.Item(1).SaveAsFile Trim(strAQSPath & "\LATEST.xls")
MsgBox ("Today's (" & Format(Date, "DD/MM/YYYY") & ") Serial Information sheet has been saved from the email." & vbNewLine & vbNewLine & "Please begin scanning all contract stock.")
FileSaved = True
Exit For
End If
End If
Next
If FileSaved = False Then
MsgBox ("Sorry, I am unable to find today's audit sheet in your emails.")
Exit Sub
End If
Any help with this will be greatly appreciated. I've got no idea what could be wrong because as you can see, the code is pretty much the same in both workbooks.