- 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.
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) orwdAlertsNone
. - 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
orOn 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?
Application.DisplayAlerts = wdAlertsNone
? What you used (False) is applicable to Excel, not Word. Word can only bewdAlertsAll
,wdAlertsMessageBox
orwdAlertsNone
.SaveAs2
and not theFileDialog
? I've seenApplication.FileDialog
, which I believe you use, misbehave in similar ways before.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.