Error When using ActiveWorkBook.SaveAs in Excel

A

Anthony

I am trying to save an Excel workbook (that has a digital signature
applied if it makes any difference) in Excel 2003 SP2 via VBA using
the ActiveWorkbook.SaveAs command, however I get the follwoing error:

Microsoft Office Excel cannot access the file 'C:\Documents and
Settings\user\Desktop'. There are several possible reasons:
- The file name or path does not exist.
- The file is being used by another program.
- The workbook you are trying to save has the same name as a
currently open workbook.

This is my code residing in the ThisWorkBook module in VBA:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

[Run some other code........................]

Dim fname As Variant
fname = Application.GetSaveAsFilename(FileFilter:="Save File As
(*.xls),*.xls", Title:="Save File As")
Application.DisplayAlerts = False
Application.EnableEvents = False

ActiveWorkbook.SaveAs fname

Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

I checked, and none of the above reasons seem to be true.

I have tried/checked the following things to no avail:
- Removed any add-ins in Excel
- Harcoded the full path/filename
- Tried saving a blank excel file with that simple line of code.
- Tried Me.SaveAs or ThisWorkbook.SaveAs
- Made sure the full file name and path were less than 200 characters
- Tried saving to other locations
- Not using IRM for Excel/Office
- Tried reinstalling office and all updates.
- Tried instyalling the hotfixes from MS KB Articles 919635 and 913770

I dont beleive this is a coding issue as it only occurs on a couple of
PC's.

Anyone have any ideas on how to fix this problem?
 
M

Mike H

I don't think it's a coding issue either becaue there doesnt appear to be
anything wrong with the code.

Have you checked the priveleges for the users who are having a problem, are
they allowed to save to the desktop?

Mike
 
N

Norman Yuan

I do not understand your logic here:

The Workbook_BeforeSave event occurs due to a "Save" command that HAS BEEN
ISSUED. This event enables to insert some code right before the saving is
committed. In your code, you can do something, such as check some
conditions. Then you can decide whether you wna the saving go ahead or
cancel it. So, I think, the code you show (after "[Run some other code...])
does not make sense: it just does what Excel would do after the event
handling procedure, since you did not cancel it.

So, unless the [Run some other code...] part results in some condition that
you have to cancel the saving, you do not need the last portion of the code,
just let Excel finish the saving.

Of course the code could make sure only when the the Workbook where the
Workbook_BeforeSave event associated to is not the ActiveWorkBook, whoch you
try to save in the event handler. That is you have multiple Workbooks open
and somehow your code or Excel is to save a non-active Workbook which
triggers the event, in which you want to save ActiveWorkbook.

I just wondering, if the Workbook that raises the BeforeSave event is the
ActiveWorkbook, shouldn't you fall into a dead loop: you/user do something
to start save it->BeforeSave fires->your code in BefreSave handler hijack
the saving and tries to save it->another BeforeSave even fires->your code
runs again, and a new SaveAs command called->BeforeSave fires->....



Anthony said:
I am trying to save an Excel workbook (that has a digital signature
applied if it makes any difference) in Excel 2003 SP2 via VBA using
the ActiveWorkbook.SaveAs command, however I get the follwoing error:

Microsoft Office Excel cannot access the file 'C:\Documents and
Settings\user\Desktop'. There are several possible reasons:
- The file name or path does not exist.
- The file is being used by another program.
- The workbook you are trying to save has the same name as a
currently open workbook.

This is my code residing in the ThisWorkBook module in VBA:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

[Run some other code........................]

Dim fname As Variant
fname = Application.GetSaveAsFilename(FileFilter:="Save File As
(*.xls),*.xls", Title:="Save File As")
Application.DisplayAlerts = False
Application.EnableEvents = False

ActiveWorkbook.SaveAs fname

Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

I checked, and none of the above reasons seem to be true.

I have tried/checked the following things to no avail:
- Removed any add-ins in Excel
- Harcoded the full path/filename
- Tried saving a blank excel file with that simple line of code.
- Tried Me.SaveAs or ThisWorkbook.SaveAs
- Made sure the full file name and path were less than 200 characters
- Tried saving to other locations
- Not using IRM for Excel/Office
- Tried reinstalling office and all updates.
- Tried instyalling the hotfixes from MS KB Articles 919635 and 913770

I dont beleive this is a coding issue as it only occurs on a couple of
PC's.

Anyone have any ideas on how to fix this problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top