1

I have a macro that creates 17 workbooks in a loop. When it's done working on a workbook it closes it and goes to the next with:

ActiveWorkbook.Save
ActiveWindow.Close

This has always worked fine until recently. Suddenly on loop nr. 7 it say (the 6 loops before still working fine):

Run-time '-2147417848 (80010108)':

Method 'Close' of objekt 'Window' failed

I can delete "ActiveWindow.Close" and close all the workbooks manually to make the macro work. But still...

Any knows why it does this?

6
  • It can be related to language settings, have you added any languages or fonts recently? Or upgraded with a Service Pack? Here's a page that talks about some of the possibilities, but depends on what your code is doing. Commented Aug 26, 2011 at 8:58
  • Have you tried putting in a wait period? Commented Aug 26, 2011 at 8:59
  • do you mean "creates 17 workbooks in a loop" ? Commented Aug 26, 2011 at 9:03
  • at iDevlop - Yes. at Remou - no, I can Try. Thanks Commented Aug 26, 2011 at 9:14
  • Edited to reflect this and avoid confusion. Commented Aug 26, 2011 at 9:20

3 Answers 3

5

As per comment.

A wait period may solve this problem.

Sign up to request clarification or add additional context in comments.

Comments

4

I'm not sure why you are using ActiveWindow.Close, perhaps that has something to do with it. The proper way to close a book (as far as I know) is:

Workbooks(excelFile).Close SaveChanges:=True

Sometimes some wacky things happen when refering to the active object, so it's best to be explicit.

Comments

0

I use the number of the window... i.e. I know this will be Window #1, so I refer to it that way. Example:

Windows(1).Close SaveChanges:=False

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.