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
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
msoFileDialogSaveAs
-- same messageApplication.DisplayAlert = False
(I know but I was desperate) or wdAlertsNone
. - Does not work. Message still showsOn 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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With