Hi,
Scenario: Word macro enabled documents live in SharePoint Document Library. User clicks .docm and the macro starts to run. It prompts the user for a file name and for a folder. Then the file is saved as a new document without macros with the file name and path provided.
Users have virtual machines. They don't have access to a C:\ drive. Their home drive with their profiles, "My Documents" and all that is on a server drive, the H:\ drive.
The problem: The SaveAs2 command triggers an error dialog on the screen "H:\dump\filename.docx" cannot be found. Check your spelling or try a different path."
Well, of course it can't be found. I'm trying to save it as a new file. That's the whole point.
The odd bit is that after displaying the message, Word goes ahead and saves the file in the folder, anyway.
I've tried 'On Error Resume Next' and I tried 'Application.DisplayAlerts = wdAlertsNone' but the message still displays.
Any idea what I can do to make the message go away? Just suppressing it would suffice, since the saving actually happens.
Here's the code.
Private Sub Document_Open()
Dim fd As FileDialog
Dim strFolder As String
Dim strDoc As String
Dim fullPath As String
Dim o As Document
Set o = ActiveDocument
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
' the original code uses a sub in a code module to get the user name.
' For the purpose of this demo, I will hard wire a value
Dim userName As String
userName = "TheUser"
' strDoc = Left(o.Name, 18) & "-" & GetUserName & "-" & Format(Now, "yyyy-mm-dd-hhMMss")
strDoc = Left(o.Name, 18) & "-" & userName & "-" & Format(Now, "yyyy-mm-dd-hhMMss")
UserForm1.frmFileName.Value = strDoc
' allow the user to change the file name
UserForm1.Show vbModal
strDoc = UserForm1.frmFileName.Value
If strDoc = "SecretPassword" Then Exit Sub ' allow Power Users a way out
GetFolder:
With fd
.Title = "Select a folder to store the draft contract"
.InitialFileName = "H:\"
If .Show = -1 Then
strFolder = .SelectedItems(1) & "\"
Else
MsgBox "Sorry, you cannot cancel at this stage. Please select a folder."
GoTo GetFolder
End If
End With
fullPath = strFolder & strDoc & ".docx"
' MsgBox fullPath
With o
' .SaveAs strFolder & strDoc & ".docx", wdFormatDocumentDefault
.SaveAs strFolder & strDoc & ".docx"
End With
MsgBox "The document will now close to remove macro code. Please reopen from you recent files list.", vbOKOnly
With o
.Close
End With
End Sub
Windows 7 Enterprise Version 6.1 Build 7601 Service Pack 1
Office Professional Plus 2010 version 14.0.6129.5000
Edit: I just noticed that the error message does not come up when the original .docm is opened via File > Recent. But if I open the file by clicking it in the SharePoint document library, I get the error. It is exactly the same file and it is in the exact same location. Go figure.
Another Edit: I just noticed that the error message does not come up when I open the file in Edit mode. I have permissions to edit files in the document library. I can select if I want to open the file in read mode or in edit mode. Read mode will be used by the common user as the default. Why is there a difference when I use "save as" whether or not the file is in read mode?
Thanks for looking,
cheers, teylyn