Thread: [Solved] Saveas error handling
View Single Post
 
Old 03-28-2012, 04:12 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I have no trouble running the code like:
Code:
Private Sub Savetemplate1_Click()
Dim myotherfilename As String, myfilename As String
ChangeFileOpenDirectory "M:\Care Plan System\"
myotherfilename = Options.DefaultFilePath(wdDocumentsPath)
myfilename = InputBox("Enter file name for document " & myfilename)
myfilename = myotherfilename + "\Care Plan System\" + myfilename
ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLTemplateMacroEnabled
Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLDocument
Application.DisplayAlerts = True
End Sub
The only differences for my system are that I need to use what for me is a valid ChangeFileOpenDirectory path and that, instead of "\Care Plan System\" I use "\".

Something I have noticed, though, is that you're using ChangeFileOpenDirectory before storing wdDocumentsPath. That means the wdDocumentsPath = "M:\Care Plan System\". Perhaps you need to reverse the order of these statements, because what you're getting now is, in effect:
myfilename = "M:\Care Plan System\Care Plan System\" + myfilename
It seems strange that you'd have a subfolder with the same name as its parent.

Also, having stored wdDocumentsPath in myotherfilename, you don't ever restore it:
Options.DefaultFilePath(wdDocumentsPath) = myotherfilename
Of course, that would be futile at the moment, because of the order in which you're using ChangeFileOpenDirectory and storing wdDocumentsPath.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote