PDA

View Full Version : Getting "file permission error" #5487



clhare
03-03-2011, 02:09 PM
I have Word templates that are based on existing templates--I just added some macros and modified others.

These templates are stored on two different servers--one in India and one in Canada. The templates are working fine in India, but when they are run in Canada, there is a sporadic 5487 error. The macros save the .doc file to a specific folder after it is initially created and then resaves the file at various points. The macros are stopping on a line of code that is simply trying to resave the file.

ActiveDocument.Save

Does anyone have any ideas on why this is happening or what I could do to fix it? I'm at a total loss!

Frosty
03-03-2011, 06:05 PM
Not to be snarky, but I would guess it is exactly what the error is giving you... whoemver is running the code doesn't necessarily have the file permissions to be able to save the document to the particular location.

It is possible to have file permissions set up (not common, but possible) which allow a user to create a file, but not modify a file... so you could very well be saving the file initially, but unable to modify (resave) the same file.

There are a lot of possibilities, but almost none of them are in the realm of vba troubleshooting.

clhare
03-03-2011, 06:28 PM
Actually, they do have the correct access. The first part of the macro does the initial save and the resave comes at the end. In some cases, they get the error at the end when it tries to resave. In other cases, it does the resave just fine and when they run a second macro on the file, it bombs when that tries to resave.

It doesn't happen every time. Today I had someone test the file several times for me. It worked for them 3 times just fine and then gave them this error on the 4th time, then worked fine the next 6 times. Same user... same template... same machine...

I don't have a clue how to resolve.

Frosty
03-03-2011, 07:06 PM
Sorry Cheryl, but you'd have to post a lot more info for anyone (even Microsoft) to be able to give you any hint as to why you intermittently can't save a document to a specific location in your particular environment.

I highly doubt it has anything to do with VBA's ActiveDocument.Save command (even if you had some code which hid the activedocument, so that there was no active document, you wouldn't get a file permissions error, you'd get an object not found error).

I would suggest doing error trapping around the offending line of code, providing the user with the option to try saving again or continuing on with the code and a suggestion to try a manual save. For example:

Sub ActiveDocumentSaveTest()
Dim sErrMessage As String
'all of your previous code

On Error GoTo l_err
ActiveDocument.Save

'reset to your other error trapping, or no error trapping (which is 0)
On Error GoTo 0
'the rest of your code
l_exit:
Exit Sub
l_err:
sErrMessage = "Unable to Save the document, do you wish to try again?"
Select Case MsgBox(sErrMessage, vbYesNo, "Wierd Error...")
Case vbYes
Resume
Case vbNo
MsgBox "Please manually save your document at the first opportunity.", vbInformation, "Please save..."
Resume Next
End Select
End Sub

At the very least, you don't want to present the end-user with a microsoft debug window (which can cause other issues with variables falling out of scope, etc).

From there, you could try logging the error manually to a txt file in some other location in order to get more datapoints as to why a network resource would be intermittently unavailable (getting date/time stamps when an ActiveDocument.Save failed, and trying to coordinate them with event logs, server logs, etc).

Unless you have code to post that someone can review... simply having an intermittent problem with ActiveDocument.Save is pretty tough to help with.

clhare
03-04-2011, 10:50 AM
This worked! I setup this error handling in the template and it just reruns that line of code--it works fine the second time--and it continues on to the end.

Thank you so much!