Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Error on closing a hidden workbook

Hi all
I have an excel template that sources it's validation lists from a separate
workbook ("Masterlist.xls") which automatically opens and hides when the
template is opened. eg:
==============================================
Sub auto_open()
Application.ScreenUpdating = False
Workbooks.Open ("D:\Masterlist.xls")
ActiveWindow.Visible = False
Application.ScreenUpdating = True
End Sub
==============================================

I now need a "BeforeClose" code to automatically close the hidden workbook
"Masterlist.xls" (without saving changes), when the template is closed.

I tried this code, but I got a Compile error "Sub or Function not defined"
msg on the row marked with the below.
============================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Schedule").Select
Range("a1").Select
Workbook("MasterList.xls").Visible = True

ActiveWindow.Close False
End Sub
=======================================
Thank for your help
BeSmart
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Error on closing a hidden workbook

Replace this:

Workbook("MasterList.xls").Visible = True

ActiveWindow.Close False


which is incorrect because it should be "Workbooks", not "Workbook" with
this:

Workbooks("MasterList.xls").Close False

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"BeSmart" wrote in message
...
Hi all
I have an excel template that sources it's validation lists from a
separate
workbook ("Masterlist.xls") which automatically opens and hides when the
template is opened. eg:
==============================================
Sub auto_open()
Application.ScreenUpdating = False
Workbooks.Open ("D:\Masterlist.xls")
ActiveWindow.Visible = False
Application.ScreenUpdating = True
End Sub
==============================================

I now need a "BeforeClose" code to automatically close the hidden workbook
"Masterlist.xls" (without saving changes), when the template is closed.

I tried this code, but I got a Compile error "Sub or Function not defined"
msg on the row marked with the below.
============================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Schedule").Select
Range("a1").Select
Workbook("MasterList.xls").Visible = True

ActiveWindow.Close False
End Sub
=======================================
Thank for your help
BeSmart



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Error on closing a hidden workbook

Thanks Rob - too easy....
BeSmart


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error on closing a hidden workbook


Hello,
I have a similar set-up;
Workbook ("Data.xls") is a shared workbook that opens ("View.xls") via
the following:

Private Sub Workbook_Open()
Workbooks.Open Filename:="(full path to workbook View.xls)",
updateLinks:=0
ActiveWorkbook.UpdateRemoteReferences = False
Workbooks("View.xls").Worksheets("Menu").Activate
Windows("Data.xls").Activate
ActiveWindow.Visible = False
End Sub

Data.xls remains hidden except when posted to via macros in View.xls.
View.xls is linked to Data.xls but the link is updated only manually.

All of that works like a charm, my problems come in trying to get both
workbooks to close, without saving either, when the user closes
View.xls.

Currently, I have the following in View.xls:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Workbooks("GuestData.xls").Close False
ActiveWorkbook.Close False
End Sub

Which gives me - Run-time error 9, subscript out of range.

I have tried so many variations and am at my (very limited) wits end.
Any help would be greatly appreciated.
Thanks,
Susan
Excel 2000, Windows xp


--
K521
------------------------------------------------------------------------
K521's Profile: http://www.excelforum.com/member.php...o&userid=27495
View this thread: http://www.excelforum.com/showthread...hreadid=261490

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
Error when closing file mmkathan Excel Discussion (Misc queries) 2 April 29th 09 05:30 PM
Error message adaytum.xla when closing workbook in Excel 2003 Laura2008 Excel Discussion (Misc queries) 1 November 5th 08 06:36 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
EXCEL.EXE has generated an error...when closing a workbook HEIKKILÄT Excel Programming 1 September 17th 03 09:16 PM


All times are GMT +1. The time now is 10:26 PM.

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"