J
JP
I'm working with an Excel 2003 workbook that has lots of code in Visual
Basic. I am logged into a server domain at work, and the workbook is saved
on a share drive that only I have access to. The workbook is not shared or
password protected.
After entering some code, I tried to save the workbook and Excel gave me the
following 3 error prompts:
1st error message: "Your changes could not be saved to 'workbookname.xls'
because of a sharing violation. Try saving to a different file."
2nd message: "[Drive]:\[Folder]\23d7200.xls count no be found. Check the
spelling og the file name, and verify the file location is correct."
3rd message: Your changes could no be saved to 'workbook name.xls', but were
saved to a temporary document named '23d7200'. Close the existing document,
then open the temporary document and save it under a new name."
After the messages, attempting to save the document again failed; I got the
message "Document not saved."
I re-opened and re-entered my code line-by-line, saving after each
successfully until I entered the line: "Dim myAttachments As
Outlook.Attachments" (See the full code below). The code is simple: loop
through the elements of an array of file names, and add the path to an email
as an attachment. I can't figure out why on this specific line Excel stops
allowing me save.
Can someone please help!!!
Code:
Sub DisplayEmail(attachmentlist As Variant)
Dim myolApp As Outlook.Application
Set myolApp = GetObject(, "Outlook.Application")
Dim myMail As Outlook.MailItem
Set myMail = myolApp.CreateItem(olMailItem)
Dim myAttachments As Outlook.Attachments ' HERES THE CULPRIT
Set myAttachments = myMail.Attachments
For i = 0 To UBound(attachmentlist)
myAttachments.Add attachmentlist(i)
Next i
With myMail
.To = "(e-mail address removed)"
.Body = "Attachment test"
.Display
End With
set myAttachments = Nothing
Set myMail = Nothing
Set myolApp = Nothing
End Sub
Basic. I am logged into a server domain at work, and the workbook is saved
on a share drive that only I have access to. The workbook is not shared or
password protected.
After entering some code, I tried to save the workbook and Excel gave me the
following 3 error prompts:
1st error message: "Your changes could not be saved to 'workbookname.xls'
because of a sharing violation. Try saving to a different file."
2nd message: "[Drive]:\[Folder]\23d7200.xls count no be found. Check the
spelling og the file name, and verify the file location is correct."
3rd message: Your changes could no be saved to 'workbook name.xls', but were
saved to a temporary document named '23d7200'. Close the existing document,
then open the temporary document and save it under a new name."
After the messages, attempting to save the document again failed; I got the
message "Document not saved."
I re-opened and re-entered my code line-by-line, saving after each
successfully until I entered the line: "Dim myAttachments As
Outlook.Attachments" (See the full code below). The code is simple: loop
through the elements of an array of file names, and add the path to an email
as an attachment. I can't figure out why on this specific line Excel stops
allowing me save.
Can someone please help!!!
Code:
Sub DisplayEmail(attachmentlist As Variant)
Dim myolApp As Outlook.Application
Set myolApp = GetObject(, "Outlook.Application")
Dim myMail As Outlook.MailItem
Set myMail = myolApp.CreateItem(olMailItem)
Dim myAttachments As Outlook.Attachments ' HERES THE CULPRIT
Set myAttachments = myMail.Attachments
For i = 0 To UBound(attachmentlist)
myAttachments.Add attachmentlist(i)
Next i
With myMail
.To = "(e-mail address removed)"
.Body = "Attachment test"
.Display
End With
set myAttachments = Nothing
Set myMail = Nothing
Set myolApp = Nothing
End Sub