6
  • SharePoint 2010
  • Word 2010
  • Windows 7 Enterprise

I have a .docm file that lives in a SharePoint document library. When it is opened, a macro fires and prompts the user for a new file name and folder and then uses .SaveAs2 to save a copy of the file in the specified location as a .docx without the macro.

I cannot use SP content types with a proper .dotm as the template, since there are over 30 different file templates in the library. I have to use the .docm in a SharePoint library and then make sure that the user saves a copy of the file to their personal drive.

So I use some code in the open event. I let the user specify a folder and a file name. Then .SaveAs2 takes these parameters and saves the current file in the new path with the new name as a normal .docx file without macros. I'll spare you the details about how strFolder and strDoc are gathered. Rest assured that they exist. I have a debug.print with the full file name and it is correct.

With o
    .SaveAs2 strFolder & strDoc & ".docx", wdFormatDocumentDefault
End With

The problem is that this code brings up a message saying that the file cannot be found. enter image description here

Well, duh, I am trying to save the file in this location. Of course it does not exist. That's the point. (Note that the folder does exist.)

After the message box is closed, Word happily saves the file to the specified location.

Also, the message only pops up if the original file is opened in Read mode from SharePoint AND if the new file path is on a network drive.

The message does NOT pop up if

  • the file is opened in Edit mode (click the SharePoint file, select Edit in the next dialog), or if
  • the file is saved to a local drive (C:) or if
  • the file is opened from the File > Recent backstage dialog.

In the production system, the users will not have a choice of Edit or Read only. They will default to Read only. Also the users will not be able to save to a local C:\ drive, since the business system puts their profile and "My Documents" on a network drive (H:).

I have tried

  • saving the file with a different approach: using msoFileDialogSaveAs -- same message
  • suppressing the message with Application.DisplayAlert = False (I know but I was desperate) or wdAlertsNone. - Does not work. Message still shows
  • suppressing the message with Application.ScreenUpdating = False. Does not work. The message still shows.
  • suppressing the message with error handling On Error Resume Next or On Error Goto MyHandler but the message pops up without the error handlers being fired. The message has the blue "i" icon, so maybe it is not interpreted as an error, but as a piece of information.

How do I make the message go away?

Also, although this is not essential, it would be nice to know:

  • Why does Read or Edit mode matter when the file is saved to a new location?
  • Why does the new location of the file (network path or local path) matter when it is saved?
  • And why does the message come up when afterwards the file saves correctly?
11
  • Application.DisplayAlerts = wdAlertsNone? What you used (False) is applicable to Excel, not Word. Word can only be wdAlertsAll, wdAlertsMessageBox or wdAlertsNone.
    – PatricK
    Commented Apr 14, 2014 at 3:22
  • Thanks, @PatricK, I tried the other options first. No cigar. I updated the post.
    – teylyn
    Commented Apr 14, 2014 at 7:45
  • I kind of assume you have, but I figure I should ask: have you verified that the line which throws the error is the SaveAs2 and not the FileDialog? I've seen Application.FileDialog, which I believe you use, misbehave in similar ways before.
    – Blackhawk
    Commented Apr 14, 2014 at 17:16
  • I can confirm that it is definitely the SaveAs2 that causes the message. In a test file I use just that command with a fixed path to the network as the only line of code in the Open() sub and it triggers the message, when the file is not in edit mode.
    – teylyn
    Commented Apr 14, 2014 at 21:56
  • This is interesting. Just out of curiosity have you tried wrapping the offending code in a catch? On Error Resume Next?
    – sten
    Commented Apr 15, 2014 at 13:03

2 Answers 2

1

After several futile attempts to change the way SharePoint serves the document in read only mode, I used the following approach to create a new Word doc, save it to the user's temp folder, copy the doc from the temp folder to the folder previously specified by the user. Now the document exists and using SaveAs does not trigger the error message.

Before the code below runs, the user has defined a file name (strDoc) and a folder for the document to be saved to.

' since we get an annoying message when trying to save to a network drive while
' in read only mode, we first create a new, empty file in the user's temp folder,
' then copy that empty file to the specified folder
' set the temp folder and full path
tempFolder = Environ("Temp")
tempPath = tempFolder & "\" & strDoc & ".docx"
' create a new document
Documents.Add DocumentType:=wdNewBlankDocument
ChangeFileOpenDirectory tempFolder
' save to temp folder and close
With ActiveDocument
    .SaveAs2 tempPath, wdFormatDocumentDefault
    .Close
End With
' copy from temp folder to previously defined destination
FileCopy tempPath, fullPath
' delete the temp file
KillFile = tempPath
' finally, save the contract over the empty file
With o
    .SaveAs2 fullPath, wdFormatDocumentDefault
End With
0

Here's a shot in the dark based on some googling and similar experience: http://blogs.technet.com/b/wordonenotesupport/archive/2009/02/07/word-2007-file-save-errors-an-error-is-displayed-when-attempting-to-save-a-word-document.aspx

The relevent bits:

  • "<path and file name>" cannot be found. Check your spelling, or try a different path.

  • <path and file name> is currently in use. Try again later.

  • Word cannot complete the save to due to a file permissions error.

You might see the aforementioned errors if Word 2007 is having a conflict with antivirus software. Most of these conflicts have been addressed by the antivirus software manufacturers, but you must download and install updates or patches for the antivirus software (not just new virus definitions) to resolve the issue. See the software manufacturer's web site for possible updates and for knowledge base articles concerning configuration issues.

...and then from McAfee describing a related issue: https://kc.mcafee.com/corporate/index?page=content&id=KB75449

Most forum discussions I found implicate server-side realtime anti-virus scanning - something about the interplay of behavior between the saving mechanism of Office 2010 not playing nice with live, access-based file scanning.

Even if this doesn't solve your issue, hope it helps!

2
  • Thanks for your time. I've seen these virus checker related posts. I don't think they apply, though. Otherwise, how come the file saves fine when it is in edit mode? Would that make a difference to the virus checker? Also, in the virus checker related posts, users could not save manually. I can do that without problems. The message only shows when Saveas is used in VBA. And then, of course, there is the fact that the file does get saved, despite the message. So, how can I make the message go away? That's all I'm after, really.
    – teylyn
    Commented Apr 14, 2014 at 22:03
  • @teylyn Ah, thanks for the clarification. If I get the chance to poke around the internet again today, I'll bear those points in mind :)
    – Blackhawk
    Commented Apr 15, 2014 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.