Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Workbook doesn't fully close - sorta

Hi,
Im trying to fully close a workbook via VBA in XL 2007 and having some
problems with it. Specifically, the Project window in the VBE still shows the
workbook. What Im doing is creating a workbook based on a template and when
the User is done they simply X out of it and all of it works correctly,
except for what remains in the VBE. I can re-open and manipulate the workbook
created from the template, but the VBE still shows it. The code for the
template (ThisWorkbook) is:

Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The Personal.xls code, in a standard module, is:

Sub EndIt(Cancel As Boolean)
ChDir extPath & grade
ActiveWorkbook.SaveAs extPath & grade & "\" & fName, FileFormat:=52
ActiveWorkbook.Close
Application.Caption = Empty
End Sub

At the time the code reaches the BeforeClose event, the following
conditions of the workbook a

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

There are no additional add-ins and it doesnt seem to cause any problems,
however, from time to time, Excel does abend and wants me to send an error
report. Does anyone know why the workbook I create from the template appears
to close correctly in Excel, but not in the VBE Project window and what I
have to do to fix it?
Thanks.
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Workbook doesn't fully close - sorta

remove this line

ActiveWorkbook.Close

from the EndIt procedure --- you're already closing the workbook, as its
that workbooks beforeclose event that fires off.

"Mark" wrote in message
...
Hi,
Im trying to fully close a workbook via VBA in XL 2007 and having some
problems with it. Specifically, the Project window in the VBE still shows
the
workbook. What Im doing is creating a workbook based on a template and
when
the User is done they simply X out of it and all of it works correctly,
except for what remains in the VBE. I can re-open and manipulate the
workbook
created from the template, but the VBE still shows it. The code for the
template (ThisWorkbook) is:

Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The Personal.xls code, in a standard module, is:

Sub EndIt(Cancel As Boolean)
ChDir extPath & grade
ActiveWorkbook.SaveAs extPath & grade & "\" & fName, FileFormat:=52
ActiveWorkbook.Close
Application.Caption = Empty
End Sub

At the time the code reaches the BeforeClose event, the following
conditions of the workbook a

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

There are no additional add-ins and it doesnt seem to cause any problems,
however, from time to time, Excel does abend and wants me to send an error
report. Does anyone know why the workbook I create from the template
appears
to close correctly in Excel, but not in the VBE Project window and what I
have to do to fix it?
Thanks.
Mark

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Workbook doesn't fully close - sorta

Thanks, Patrick. I removed that line and tried it again, but I still have the
workbook showing in the Project window. It shows VBAProject (xxxxx.xlsm) and
directly below it VBAProject (Personal.xls)

"Patrick Molloy" wrote:

remove this line

ActiveWorkbook.Close

from the EndIt procedure --- you're already closing the workbook, as its
that workbooks beforeclose event that fires off.

"Mark" wrote in message
...
Hi,
Im trying to fully close a workbook via VBA in XL 2007 and having some
problems with it. Specifically, the Project window in the VBE still shows
the
workbook. What Im doing is creating a workbook based on a template and
when
the User is done they simply X out of it and all of it works correctly,
except for what remains in the VBE. I can re-open and manipulate the
workbook
created from the template, but the VBE still shows it. The code for the
template (ThisWorkbook) is:

Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The Personal.xls code, in a standard module, is:

Sub EndIt(Cancel As Boolean)
ChDir extPath & grade
ActiveWorkbook.SaveAs extPath & grade & "\" & fName, FileFormat:=52
ActiveWorkbook.Close
Application.Caption = Empty
End Sub

At the time the code reaches the BeforeClose event, the following
conditions of the workbook a

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

There are no additional add-ins and it doesnt seem to cause any problems,
however, from time to time, Excel does abend and wants me to send an error
report. Does anyone know why the workbook I create from the template
appears
to close correctly in Excel, but not in the VBE Project window and what I
have to do to fix it?
Thanks.
Mark

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Workbook doesn't fully close - sorta

Do you have a variable which is referencing the workbook? If so, it should
be set to Nothing after you close the workbook. Here is a macro that
demonstrates similar behavior you see:

1. Create a workbook called A.xls. Add a module with some code.

2. Create a 2nd workbook, add a module and run the following macro:

Public wkb As Workbook
Sub Test()
Set wkb = Workbooks("A.xls")
End Sub

3. Close A.xls

4. Go back to the VBE and A.xls is still there and the code is visible too.

5. Click the Stop button. A.xls is cleared out.

Now perform the steps again with a modified macro, and omit Step 5.

Sub Test()
Set wkb = Workbooks("A.xls")
Set wkb = Nothing
End Sub

A.xls is no longer available.

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

http://www.higherdata.com/sql/batchsqlfromexcel.html
Create batch SQL from Excel


"Mark" wrote in message
...
Thanks, Patrick. I removed that line and tried it again, but I still have
the
workbook showing in the Project window. It shows VBAProject (xxxxx.xlsm)
and
directly below it VBAProject (Personal.xls)

"Patrick Molloy" wrote:

remove this line

ActiveWorkbook.Close

from the EndIt procedure --- you're already closing the workbook, as its
that workbooks beforeclose event that fires off.

"Mark" wrote in message
...
Hi,
Im trying to fully close a workbook via VBA in XL 2007 and
having some
problems with it. Specifically, the Project window in the VBE still
shows
the
workbook. What Im doing is creating a workbook based on a template
and
when
the User is done they simply X out of it and all of it works
correctly,
except for what remains in the VBE. I can re-open and manipulate the
workbook
created from the template, but the VBE still shows it. The code for the
template (ThisWorkbook) is:

Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The Personal.xls code, in a standard module, is:

Sub EndIt(Cancel As Boolean)
ChDir extPath & grade
ActiveWorkbook.SaveAs extPath & grade & "\" & fName, FileFormat:=52
ActiveWorkbook.Close
Application.Caption = Empty
End Sub

At the time the code reaches the BeforeClose event, the following
conditions of the workbook a

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

There are no additional add-ins and it doesnt seem to cause any
problems,
however, from time to time, Excel does abend and wants me to send an
error
report. Does anyone know why the workbook I create from the template
appears
to close correctly in Excel, but not in the VBE Project window and what
I
have to do to fix it?
Thanks.
Mark



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Workbook doesn't fully close - sorta

Thanks, Tim. I went through the code and everywhere that I referenced a
workbook through a variable, I reset to "Nothing." However, I still have the
same problem. When I click on 'File', in the VBE, the first item in the list
is wanting me to save the workbook (xxxxx.xlsm) created via the template
(*.xltm).
Aside from the template extension, the only thing that I can think of that I
have done differently with this set of templates is adding a command button
(ActiveX) to the sheets, instead of adding options to the QAT or the ribbon.
Each command button simply unhides the next sheet in the workbook.
If I use a template with an extension of .xlt, then I don't seem to have the
problem. However, I was under the impression that the proper extension for
the templates was .xltm, since they contained macros. Am I making a mistake
on the extension?
Mark

"Tim Zych" wrote:

Do you have a variable which is referencing the workbook? If so, it should
be set to Nothing after you close the workbook. Here is a macro that
demonstrates similar behavior you see:

1. Create a workbook called A.xls. Add a module with some code.

2. Create a 2nd workbook, add a module and run the following macro:

Public wkb As Workbook
Sub Test()
Set wkb = Workbooks("A.xls")
End Sub

3. Close A.xls

4. Go back to the VBE and A.xls is still there and the code is visible too.

5. Click the Stop button. A.xls is cleared out.

Now perform the steps again with a modified macro, and omit Step 5.

Sub Test()
Set wkb = Workbooks("A.xls")
Set wkb = Nothing
End Sub

A.xls is no longer available.

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

http://www.higherdata.com/sql/batchsqlfromexcel.html
Create batch SQL from Excel


"Mark" wrote in message
...
Thanks, Patrick. I removed that line and tried it again, but I still have
the
workbook showing in the Project window. It shows VBAProject (xxxxx.xlsm)
and
directly below it VBAProject (Personal.xls)

"Patrick Molloy" wrote:

remove this line

ActiveWorkbook.Close

from the EndIt procedure --- you're already closing the workbook, as its
that workbooks beforeclose event that fires off.

"Mark" wrote in message
...
Hi,
Iâm trying to âœfully❠close a workbook via VBA in XL 2007 and
having some
problems with it. Specifically, the Project window in the VBE still
shows
the
workbook. What Iâm doing is creating a workbook based on a template
and
when
the User is done they simply âœX❠out of it and all of it works
correctly,
except for what remains in the VBE. I can re-open and manipulate the
workbook
created from the template, but the VBE still shows it. The code for the
template (ThisWorkbook) is:

Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The Personal.xls code, in a standard module, is:

Sub EndIt(Cancel As Boolean)
ChDir extPath & grade
ActiveWorkbook.SaveAs extPath & grade & "\" & fName, FileFormat:=52
ActiveWorkbook.Close
Application.Caption = Empty
End Sub

At the time the code reaches the BeforeClose event, the following
conditions of the workbook a

Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True

There are no additional add-ins and it doesnât seem to cause any
problems,
however, from time to time, Excel does abend and wants me to send an
error
report. Does anyone know why the workbook I create from the template
appears
to close correctly in Excel, but not in the VBE Project window and what
I
have to do to fix it?
Thanks.
Mark






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if Workbook fully loaded... Matt[_41_] Excel Programming 1 July 20th 09 07:02 PM
When I open a workbook, cell protection is not fully active Dave_B_at C&W Excel Worksheet Functions 0 February 4th 09 10:42 AM
Open New Workbook / Save and Close Current Workbook Joe K. Excel Programming 1 December 7th 07 08:04 PM
VLOOKUP(sorta) againts SQL Server table - HELP! cpa-mcse.net Excel Worksheet Functions 2 November 29th 07 04:31 PM
Chart Wizard sorta broken. themeanies Charts and Charting in Excel 4 October 26th 05 03:06 PM


All times are GMT +1. The time now is 04:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"