Close Excel Runtime 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 About Us Learn more about Stack Overflow the
Excel 2007 Runtime Error
company Business Learn more about hiring developers or posting ads with us Stack Overflow excel runtime error 5 Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
Excel Runtime Error 53
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Workbook.Close() causes “Run-time error 9” up vote 0 down vote favorite I am somewhat new to VBA, and I excel runtime error 429 am trying to make a Sub() which reads data from a different Excel Workbook. It works by opening the workbook, reading from it, and then I would like to close the workbook again. The last part is what causes the following error: Run-time error '9': Subscript out of range I fail to see why I get this error, when trying to close a file. I hope you guys can assits. It works if excel runtime error 1004 I comment out the Close() part... Code Option Explicit Sub Test() Dim Path, Filename Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet, transmitWorkbook As Workbook, revieveWorkbook As Workbook 'Define a variable for the workbook which is to recieve data Set revieveWorkbook = ActiveWorkbook Path = "C:\Test Folder\" Filename = "FileToReadFrom.xlsx" 'Open workbook which is to transmit, if its not already open If Is_WorkBook_Open(Path & Filename) Then Set transmitWorkbook = Workbooks(Path & Filename) Else Set transmitWorkbook = Workbooks.Open(Path & Filename) End If revieveWorkbook.Sheets(1).Range("A1").Value = transmitWorkbook.Sheets(2).Range("F9").Value revieveWorkbook.Sheets(1).Range("B1").Value = Month(transmitWorkbook.Sheets(2).Range("H9").Value) Workbooks(Path & Filename).Close SaveChanges:=False End Sub excel vba excel-vba share|improve this question asked Sep 17 '15 at 9:30 Noceo 170112 2 why don't you use transmitterworkbook.close false? –psychicebola Sep 17 '15 at 9:32 As I said, I'm pretty new to VBA. I just used the MSDN documentation for closing workbooks. Your suggestion seems to work though. However I still dont get why my original code does not work? –Noceo Sep 17 '15 at 9:33 try it with the transmitworkbook variable. –psychicebola Sep 17 '15 at 9:35 Well, that causes the error to change to "Run-time error '13': Type mismatch" –Noceo Sep 17 '15 at 9:38 3 Try as Workbooks(Filename).Close SaveChanges:=False. An open workbook's 'name' does not include the path unl
360 games PC games
Excel Runtime Error 6 Overflow
Windows games Windows phone games Entertainment All Entertainment excel runtime error 9 Movies & TV Music Business & Education Business Students & educators
Excel Runtime Error 438
Developers Sale Sale Find a store Gift cards Products Software & services Windows Office Free downloads & security Internet http://stackoverflow.com/questions/32626935/workbook-close-causes-run-time-error-9 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 Lumia All https://support.microsoft.com/en-us/kb/210684 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
Forums Excel Questions Run-time error 1004 Method 'Close' of object '_Workbook' failed Results 1 to 7 of 7 Run-time error 1004 Method 'Close' of object '_Workbook' failedThis is http://www.mrexcel.com/forum/excel-questions/726116-run-time-error-1004-method-close-object-_workbook-failed.html a discussion on Run-time error 1004 Method 'Close' of object '_Workbook' failed within http://www.mrexcel.com/forum/excel-questions/80828-trying-close-workbook-visual-basic-applications.html the Excel Questions forums, part of the Question Forums category; Hi, I am using Excel 2003 on XP. I have various processes that open workbooks, do some operations on them ... LinkBack LinkBack URL About LinkBacks Bookmark & Share Digg this Thread!Add Thread to del.icio.usBookmark in TechnoratiTweet this thread Thread Tools runtime error Show Printable Version Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Sep 12th, 2013,06:51 AM #1 Boomer67 New Member Join Date Jan 2005 Location London Posts 16 Run-time error 1004 Method 'Close' of object '_Workbook' failed Hi, I am using Excel 2003 on XP. I have various processes that open workbooks, do some operations on them and then close them again. excel runtime error This normally works fine, but I occasionally get a problem with the code in that it throws a debug error when it gets to the close stage. The simple code is: Code: Sub DemonstrateCloseError() Workbooks.Open "C:\boomer\Open and Close.xls" ' do stuff Workbooks("Open and Close.xls").Close savechanges:=True End Sub When run the debug error highlights the close line. If I then continue the processing through F8 (step into) or F5 (Run) it continues fine - I do not change anything. This indicates that the code and the file itself are OK, but gives no reason for the halt in processing. I have even re-installed Excel in an attempt to fix but I still get the problem. Appreciate if anyone can point me to the cause. Thanks Share Share this post on Digg Del.icio.us Technorati Twitter Reply With Quote Sep 12th, 2013,07:00 AM #2 JMonty Board Regular Join Date May 2012 Posts 185 Re: Run-time error 1004 Method 'Close' of object '_Workbook' failed What happens if you use the following: Code: Sub TestOpenAndClose() Set wbk = Workbooks.Open("C:\boomer\Open and Close.xlsx") wbk.Sheets(1).Range("A20") = wbk.Sheets(1).Range("A20") + 1 wbk.Close SaveChanges:=True End Sub Run it 5 times. The next ti
Forums Excel Questions trying to close a workbook in VBA Results 1 to 5 of 5 trying to close a workbook in VBAThis is a discussion on trying to close a workbook in VBA within the Excel Questions forums, part of the Question Forums category; I'm trying to close a workbook in VBA but it's not even starting the subroutine...... the workbook name is in ... LinkBack LinkBack URL About LinkBacks Bookmark & Share Digg this Thread!Add Thread to del.icio.usBookmark in TechnoratiTweet this thread Thread Tools Show Printable Version Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Apr 4th, 2004,07:07 PM #1 Chris Davison MrExcel MVP Join Date Feb 2002 Location Millbank, London, UK Posts 1,790 trying to close a workbook in VBA I'm trying to close a workbook in VBA but it's not even starting the subroutine...... the workbook name is in cell A1, which changes, so I can't hard-code it's name :
Sub import_files()
sourceworkbook = range("A1").Value
'open source
Workbooks.Open Filename:=sourceworkbook
..... lots of copy paste stuff......
'close source workbook
Workbooks(sourceworkbook).close
End Sub
I get runtime error 9 : subscript out of range on the "Workbooks(sourceworkbook).close" line if I omit the "Workbooks(sourceworkbook).close" everything works fine, but I'm left with that workbook sitting open, which needs to be closed I know I'm missing something simple.... thanks Chris Share Share this post on Digg Del.icio.us Technorati Twitter Reply With Quote Apr 4th, 2004,07:25 PM #2 Tom Urtis MrExcel MVP Join Date Feb 2002 Location San Francisco, California USA Posts 11,068 Re: trying to close a workbook in VBA Does your "lots of copy and paste stuff" code put you on a different worksheet than the one you are on when the workbook opens and the sourceworkbook variable is declared? Try qualifying the declaration with the worksheet name parent to which the sourceworkbook variable in that A1 cell belongs, such as Worksheets("Sheet1").Range("A1").Value (or the VBA code name for the sheet instead of its tab name), and see if it helps. Share Share this post on Digg Del.icio.us Technorati Twitter Tom Urtis Microsoft MVP - Excel Reply With Quote Apr 4th, 2004,07:39 PM #3 Chris Davison MrExcel MVP Join Date Feb 2002 Location Millbank, London, UK Posts 1,790 Re: trying to close a workbook in VBA Hi Tom, thanks for looking at this yeah, it's parent is declared within a for-next loop :
Sub import_files()
For Each cell In Range(ThisWork