Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I fix  this 'subscript out of range error' ?

Posted on 2010-08-20
9
Medium Priority
?
360 Views
Last Modified: 2012-06-27
I have a workbook before close macro that produces a 'subscript out of range' error when it gets to the code below. As soon as I click out of the error, both books close. But other than resorting to 'On Error Resume Next', how do I write it so that it closes both books without the error?

Thanks,
John
Windows("AllConfigs.xls").Close Saved = True
ThisWorkbook.Close Saved = True

Open in new window

0
Comment
Question by:gabrielPennyback
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 20

Accepted Solution

by:
Ardhendu Sarangi earned 500 total points
ID: 33490030
check the name of the file. it might be incorrect...

if not, check this code..

Workbooks("AllConfigs.xls").Close Saved = True
ThisWorkbook.Close Saved = True

see if this works.

- Ardhendu
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 500 total points
ID: 33490045
Use Workbooks not Windows.

If the file is new, it will not have an extension, like Workbooks("Book1")
If it is an existing file, the title changes - Workbooks("Book1.xls")
0
 
LVL 5

Assisted Solution

by:jklmn
jklmn earned 500 total points
ID: 33492704
Workbooks("AllConfigs.xls").Close True
ThisWorkbook.Close True
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:gabrielPennyback
ID: 33492977
Thanks for pointing out my "Windows" typo.  
Maybe there's something wrong with my computer but as long as I have the code 'ThisWorkook.Close True' anywhere in the macro, I get the error. If you take that line away, my calling workbook still closes, but i get the "Do you want to save ..." alert, which i would like to avoid. So I tried using "Appilcation.DisplayAlerts = False," but i still got the alert. Is there some other line of code that will suppress the alert without the line 'ThisWorkook.Close True'? If there is, then that will do it.
 Please create a file named 'AllConfigs.xls' , and try closing it from your 'Book1.xls' and let me know if you get the same results.
Thanks,
John
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 33492992
Okay, I just discovered that 'On Error Resume Next' solves the problem. But that always seems like kind of a cop out. Is there any other way to fix it?
Thanks,
John
0
 
LVL 5

Expert Comment

by:jklmn
ID: 33493415
The error 'subscript out of range error' should happen in ThisWorkbook.Close True because there is no subscript at all here.
0
 
LVL 5

Expert Comment

by:jklmn
ID: 33493417
Sorry I meant
The error 'subscript out of range' should not happen in 'ThisWorkbook.Close True' because there is no subscript at all here.
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 500 total points
ID: 33499470
Do you have a BeforeSave event? What if you use:
ThisWorkbook.Save
ThisWorkbook.Close False
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 33686595
I'm good now, thanks!

- John
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question