Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2012, 02:30 AM
jillapass jillapass is offline Saveas error handling Windows 7 32bit Saveas error handling Office 2007
Novice
Saveas error handling
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default Saveas error handling

I have 2 buttons in a word document for saving, the document is an dotm which runs various macros depending on what the user inputs.

The first button is labelled 'Save as Working Document' and this simply asks the user to choose a filename and saves it as a dotm and works fine.

The second button is 'Save as Final Document' which needs to be a docx.

This second one fails, the only difference is the fileformat part of the statement.

I think I know what the problem is, but don't know what to do. If I save the document manually to a docx format it warns me that I will lose my VBA macros, but that is what I actually want.

So, my question is how do I tell the macro that I don't mind that.



This is the code.
Code:
Private Sub Savetemplate1_Click()
ChangeFileOpenDirectory "M:\Care Plan System\"
Dim myotherfilename As String
Dim myfilename As String
myotherfilename = Options.DefaultFilePath(wdDocumentsPath)
myfilename = InputBox("Enter file name for document " & myfilename)
'MsgBox myfilename
myfilename = myotherfilename + "Care Plan System\" + myfilename
MsgBox myfilename
'ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLTemplateMacroEnabled
 
ActiveDocument.SaveAs FileName:=myfilename, _
FileFormat:=wdFormatXMLDocument
 
End Sub
The first Saveas is commented, but is just there to show what the code is like that works.

Last edited by macropod; 03-27-2012 at 10:32 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 03-27-2012, 10:39 PM
macropod's Avatar
macropod macropod is offline Saveas error handling Windows 7 64bit Saveas error handling Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Hi jliiapass,

Try:
Code:
Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLDocument
Application.DisplayAlerts = True
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-28-2012, 12:51 AM
jillapass jillapass is offline Saveas error handling Windows 7 32bit Saveas error handling Office 2007
Novice
Saveas error handling
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

Sorry, same error message.

getting runtime error '4198'
command failed.

This seems to be a fairly generic error that happens whenever an error occurs that doesn't meet a specific criteria.
Reply With Quote
  #4  
Old 03-28-2012, 01:36 AM
macropod's Avatar
macropod macropod is offline Saveas error handling Windows 7 64bit Saveas error handling Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 think there's an error in your code. I believe:
"Care Plan System\"
should be:
"\Care Plan System\"
You probably also don't need:
ChangeFileOpenDirectory "M:\Care Plan System\"
which can be replaced by:
myfilename = "M:\Care Plan System\Care Plan System\" + myfilename
There also doesn't seem to be any point in having '& myfilename' in:
InputBox("Enter file name for document " & myfilename)
as 'myfilename' is empty when the InputBox runs.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-28-2012, 03:13 AM
jillapass jillapass is offline Saveas error handling Windows 7 32bit Saveas error handling Office 2007
Novice
Saveas error handling
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

Hello Paul

I have now made my code literally a few lines as show at the end as all the rest is just localisation. But, it still fails on the 2nd save wiht run-time error 4198: command failed.

I have to admit I am getting a bit frustrated now.
What I am trying to do is save a .dotm word template as a .docx using the name that the user enters, but I just don't seem to be able to achieve it. At the moment the users have to press save as and select word document, but this seems beyond their very limited ability which is why I thought I would automate it. I also need to keep a .dotm version in case they need to make changes at a later date.



myfilename = InputBox("Enter file name for document " & myfilename)
MsgBox myfilename '(this is just for me to see what I have entered)
ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLTemplateMacroEnabled
Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=myfilename, FileFormat:=wdFormatXMLDocument
Application.DisplayAlerts = True
Reply With Quote
  #6  
Old 03-28-2012, 04:12 AM
macropod's Avatar
macropod macropod is offline Saveas error handling Windows 7 64bit Saveas error handling Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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
  #7  
Old 03-28-2012, 05:06 AM
jillapass jillapass is offline Saveas error handling Windows 7 32bit Saveas error handling Office 2007
Novice
Saveas error handling
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

Hello Paul
You are being so helpful and yet I still cannot get mine to work.
I have gone back to basics and created a macro by recording the steps I am taking.

Here is the very simple bit of code, no filenames being input or anything, and yet it still fails for me.

Code:
Private Sub CommandButton1_Click()
    
    ActiveDocument.SaveAs FileName:="M:\Care Plan System\testdoc 1259.docx", _
        FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
        AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
        :=False, SaveAsAOCELetter:=False
End Sub
Reply With Quote
  #8  
Old 03-30-2012, 03:24 PM
macropod's Avatar
macropod macropod is offline Saveas error handling Windows 7 64bit Saveas error handling Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Hi jliiapass,

I'm wondering if this is a netwrok issue. What happens if you try to do a 'SaveAs' via the File SaveAs dialogue, and input 'M:\Care Plan System\testdoc 1259.docx' as the document name?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Saveas error handling Microsoft office 2010 error 2908 and error 1935 !!!!!!heeeeellpppp!!!!!!!!! bennypryde Office 1 01-05-2012 03:33 PM
Saveas error handling saveAs ChDir _ tinfanide Excel Programming 4 11-05-2011 01:40 AM
Handling Excel Data msofficeno475 Excel 1 01-17-2010 09:56 AM
Runtime error 5487 - Word cannot complete the save to to file permission error franferns Word 0 11-25-2009 05:35 AM
Handling ICALENDAR attachments l_kris06 Outlook 0 11-12-2008 07:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft