Activeworkbook.savecopyas 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 policies of this site activeworkbook.saveas runtime error 1004 About Us Learn more about Stack Overflow the company Business Learn more about
Method Saveas Of Object _workbook Failed 1004
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
Excel Vba Method 'saveas' Of Object '_workbook' Failed
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 a minute: Sign up Run time error
Runtime Error 1004 Saveas Method Of Workbook Class Failed
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 is possible to give user the option to save it at saveas method of workbook class failed vba 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 the xlsm extension. Sub Command1Click() Dim lResp As Long Dim sCurrFile As String Dim sNewFile As String Const sPROMPT As String =
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn method save of object _workbook failed more about Stack Overflow the company Business Learn more about hiring developers or posting excel vba error 1004 document not saved ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community activeworkbook.saveas fileformat Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Excel 2007 VBA ActiveWorkbook SaveAs not saving … Run-time error http://stackoverflow.com/questions/9751622/run-time-error-1004-for-saving-excel-file-vba-required 1004 up vote 2 down vote favorite I had Excel record the steps of choosing Save As and applying a specific location and file name, and it produces this VBA code: ActiveWorkbook.SaveAs Filename:= _ "H:\Documents\Data\Tasks\Transfer.xlsx" _ , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False Have also tried setting the FileFormat as FileFormat:=51 I also included the following handlers, but it doesn't work with or without them: On Error Resume Next Application.DisplayAlerts = False http://stackoverflow.com/questions/29437776/excel-2007-vba-activeworkbook-saveas-not-saving-run-time-error-1004 The original file is in .xls format. When I run the macro allowing display alerts, it produces this error: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed This used to work until I believe going to Windows 8 and a new network server at work. Could something like that affect SaveAs? What am I missing? Thanks for any tips you might have. excel vba excel-vba share|improve this question asked Apr 3 '15 at 18:32 Rusty S. 111 Does it work if you change the mapped drive (H) to a UNC, e.g., \\Server\Documents ... ? –Doug Glancy Apr 3 '15 at 19:11 1 Yes, I am able to manually able to save these .xls files as .xlsx. Good point about UNC. Sometimes the macro recorder would produce that too depending on location, so I had tried that both ways. –Rusty S. Apr 3 '15 at 19:40 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote Try this Application.ActiveWorkbook.SaveAs Filename:="H:\Documents\Data\Tasks\Transfer.xlsx", fileformat:=51 share|improve this answer answered Apr 3 '15 at 18:49 Dmitrij Holkin 8581829 Is this not one of the attempts already made by OP? –pnuts Apr 3 '15 at 19:02 add a comment| Yo
One games Xbox 360 games PC https://support.microsoft.com/en-us/kb/928283 games Windows games Windows phone games Entertainment All Entertainment Movies & TV Music Business & Education Business Students & http://www.vbaexpress.com/forum/showthread.php?39523-Solved-ActiveWorkbook-SaveAs-xlsm-help! educators Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security error 1004 Internet Explorer Microsoft Edge Skype OneNote OneDrive Microsoft Health MSN Bing Microsoft Groove Microsoft Movies & TV Devices & Xbox All Microsoft devices Microsoft Surface All Windows PCs & tablets PC accessories Xbox & games Microsoft Band Microsoft runtime error 1004 Lumia All Windows phones Microsoft HoloLens For business Cloud Platform Microsoft Azure Microsoft Dynamics Windows for business Office for business Skype for business Surface for business Enterprise solutions Small business solutions Find a solutions provider Volume Licensing For developers & IT pros Develop Windows apps Microsoft Azure MSDN TechNet Visual Studio For students & educators Office for students OneNote in classroom Shop PCs & tablets perfect for students Microsoft in Education Support Sign in Cart Cart Javascript is disabled Please enable javascript and refresh the page Cookies are disabled Please enable cookies and refresh the page CV: {{ getCv() }} English (United States) Terms of use Privacy & cookies Trademarks © 2016 Microsoft
VBA Code & Other Help Excel Help Solved: ActiveWorkbook.SaveAs xlsm help! If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 7 of 7 Thread: Solved: ActiveWorkbook.SaveAs xlsm help! Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 10-22-2011,08:00 AM #1 Andybuck86 View Profile View Forum Posts View Blog Entries View Articles VBAX Regular Joined Aug 2010 Posts 32 Location Solved: ActiveWorkbook.SaveAs xlsm help! You guys have helped me out plenty of times in the past and I'm hoping you can do the same again for me! I have the following code as a module in my workbook Option Explicit Sub Save_Password() Application.DisplayAlerts = False Dim Open_Password As String Dim New_File_Name As String New_File_Name = Sheets("QryData").Range("J32").Value & "\" & Sheets("QryData").Range("J31").Value & ".xlsm" Open_Password = InputBox("Please enter a password") ActiveWorkbook.SaveAs New_File_Name, _ WriteResPassword:=Open_Password, _ Password:="test" ' ActiveWorkbook.SaveAs New_File_Name, _ ' creates a new file with the name in G1 ' Password:=Open_Password, _ ' this is the password the user enters ' WriteResPassword:="password" ' this is the master password End Sub Formatting tags added by mark007 This worked great until I decided I wanted to save my spreadsheet as a template. After this when I run my code I get a run-time error 1004 I have searched forums and think I need to add something like this : fileformat:=52 52 = xlOpenXMLWorkbookMacroEnabled But I keep getting compile errors... Any ideas? Reply With Quote 10-22-2011,01:53 PM #2 MCraiss View Profile View Forum Posts View Blog Entries View Articles VBAX Newbie Joined Oct 2011 Posts 2 Location It seems to me, that this has something to do with access rights. When I execute the following command on my Win7 machine I also get an error 1004: ActiveWorkbook.SaveAs "c:\