Activeworkbook.saveas Cancel Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and activeworkbook.saveas runtime error 1004 policies of this site About Us Learn more about Stack Overflow the
Vba Runtime Error 1004 Method Saveas Of Object _workbook Failed
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Excel Vba Saveas Error Handling
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes
Runtime Error 1004 Saveas Method Of Workbook Class Failed
a minute: Sign up Run time error 1004 for saving excel file (VBA required) up vote 3 down vote favorite 2 I was wondering if anyone knows how to use vba to save a .txt file that is opened in excel? I have tried writing a coding with a UserForm, but it is giving me errors. I was wondering if it excel vba error 1004 document not saved is possible to give user the option to save it at his/her favourite spot, and also his/her favorite name? Public Sub CommandButton1_Click() Dim YesOrNoAnswerToMessageBox As String Dim QuestionToMessageBox As String Dim CurrentFile As String QuestionToMessageBox = "Do you want to save?" YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Save file") If YesOrNoAnswerToMessageBox = vbNo Then Unload Me 'Cancellation command Else CurrentFile = ThisWorkbook.FullName ActiveWorkbook.SaveAs "C:\myfile.xls", FileFormat:=52 Workbooks.Open CurrentFile End If End Sub excel vba excel-vba share|improve this question edited Mar 17 '12 at 22:59 brettdj 38.5k1563109 asked Mar 17 '12 at 16:22 user1204868 3215926 MsgBox returns a Long but you are coercing it into a String. Then you are coercing it back into a Long in order to compare it to vbNo, a Long constant. It would be cleaner to avoid this back-and-forth casting by declaring it as Dim YesOrNoAnswerToMessageBox As Long instead. –Jean-Francois Corbett Mar 19 '12 at 8:51 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted The error is because your file extension (xls) doesn't match your file type (OpenXMLWorkbookMacroEnabled). You would need th
soon) Ruby (coming soon) Getting Started Code Samples Resources Patterns and Practices App Registration Tool Events Podcasts Training API Sandbox Videos Documentation Office Add-ins Office Add-in Availability Office excel vba method 'saveas' of object '_workbook' failed Add-ins Changelog Microsoft Graph API Office 365 Connectors Office 365 REST APIs activeworkbook.saveas fileformat SharePoint Add-ins Office UI Fabric Submit to the Office Store All Documentation https://www.yammer.com/ http://feeds.feedburner.com/office/fmNx Ask a question Quick access fileformat 52 Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: VBA SaveAs Macro enabled workbook fails with choice Cancel or No buttons Microsoft Office for Developers http://stackoverflow.com/questions/9751622/run-time-error-1004-for-saving-excel-file-vba-required > Excel for Developers Question 0 Sign in to vote Hi there :) The following VBA code to SaveAs Macro enabled workbook fails. Once you make your choice to use existing file name you are prompt to overwrite the existing file. The massage is: A file named ‘zzzz’ already exist in this location. Do you want to replace it? If you push https://social.msdn.microsoft.com/Forums/office/en-US/feb54dd6-f85b-4cf1-b27a-0691ce100e76/vba-saveas-macro-enabled-workbook-fails-with-choice-cancel-or-no-buttons?forum=exceldev ‘No’ or ‘Cancel’ following error massage is generated: Run time error 1004 Cannot access ‘zzzz.xlms’ VBA code stops at the line: ThisWorkbook.SaveAs Filename:=FileSaveName, FileFormat:=52 Here is the code to test: Sub Rectangle1_Click() Dim fPath As String Dim FileSaveName As String fPath = Application.DefaultFilePath & "\" FileSaveName = Application.GetSaveAsFilename(InitialFileName:="zzzz", filefilter:="Excel Files(*.xlsm),*.xlsm") ThisWorkbook.SaveAs Filename:=FileSaveName, FileFormat:=52 End Sub I’m looking for the following solution: If “No” button is pressed then file save dialog window reopens If “Cancel” then it exits Any support to solve this case is welcome. Thanks in advance for your help to finalize this code Regards :) Wednesday, September 05, 2012 10:12 AM Reply | Quote Answers 3 Sign in to vote This might be more than you were looking for but should cover most scenarios, with chances to 'try again' where appropriate. Eg does the file already exist and if so is it open, is the filename same as current name if so do Save vs SaveAs. Option Explicit Sub test() Dim sInitF As String Dim sFilter As String Dim sFileName As String sInitF = "zzzz.xlsm" sFilter = "Excel Files(*.xlsm),*.xlsm" If GetSaveAs(sInitF, sFilte
hope there is a really simple answer to this but I have not been abl to find a simple solution to error trapping the ActiveWorkbook.SaveA method. When http://www.pcreview.co.uk/threads/error-on-activeworkbook-saveas-method.977695/ the following command runs (inside a macro) and I selec 'yes' from the dialog box when it says "the file already exists do want to replace it?" - that's fine. When I select 'no' or 'cancel' th following error occurs... Runtime Error 1004: "Method 'SaveAs' o object '_workbook' failed The method is: (where sWorkBookPath and sFileName are variables for m path and filename) ActiveWorkbook.SaveAs error 1004 Filename:=sWorkBookPath & "\" _ & sFileName & ".txt", FileFormat:=xlText, CreateBackup:=False How do I stop the macro crashing when I select 'no' Kindy Regards And -- Message posted from http://www.ExcelForum.com cruisy, May 17, 2004 #1 Advertisements Guest Guest >>try putting in either On Error Resume Next >>O On Error Goto >>Or handle the specific erro On Error GoTo ErrHandler >>>> ErrHandler If Err.Number runtime error 1004 = 1004 And Err.Description = "Method 'SaveAs' of object '_workbook' failed" The Resume Nex End If >>Make sure you match the description exactly as it shows up in the error ----- cruisy > wrote: ---- Hi there I hope there is a really simple answer to this but I have not been abl to find a simple solution to error trapping the ActiveWorkbook.SaveA method. When the following command runs (inside a macro) and I selec 'yes' from the dialog box when it says "the file already exists do want to replace it?" - that's fine. When I select 'no' or 'cancel' th following error occurs... Runtime Error 1004: "Method 'SaveAs' o object '_workbook' faile The method is: (where sWorkBookPath and sFileName are variables for m path and filename ActiveWorkbook.SaveAs Filename:=sWorkBookPath & "\" & sFileName & ".txt", FileFormat:=xlText, CreateBackup:=Fals How do I stop the macro crashing when I select 'no Kindy Regard And -- Message posted from http://www.ExcelForum.com Guest, May 17, 2004 #2 Advertisements Tim Zych Guest If you always want to save the workbook, this macro won't ask any questions. It will just save. Application.DisplayAlerts = False ActiveWor