PC Review


Reply
Thread Tools Rate Thread

"Document not saved" error after typing a line of code in Excel VB

 
 
=?Utf-8?B?SlA=?=
Guest
Posts: n/a
 
      27th Jul 2007
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 Removed)"
.Body = "Attachment test"
.Display
End With

set myAttachments = Nothing
Set myMail = Nothing
Set myolApp = Nothing
End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Document not saved" "error in loading DLL" Tracey L Microsoft Excel Misc 0 1st Dec 2008 12:57 PM
Excel "Document not saved" error jcf Microsoft Excel Misc 3 16th Apr 2008 12:10 PM
"Document not saved"/ sharing violation after entering VB code =?Utf-8?B?SlA=?= Microsoft Excel Crashes 0 27th Jul 2007 03:34 AM
Excel "Disk is Full" "Document Cannot Be Saved" Errors Denard Springle Microsoft Excel Crashes 5 19th Dec 2003 02:06 PM
Re: I get error "The disk is full" - the "Document not saved." Lowland Microsoft Windows 2000 0 21st Aug 2003 01:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:01 PM.