View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
SusanK521 SusanK521 is offline
external usenet poster
 
Posts: 3
Default Closing Hidden Workbook when Active Workbook is Closed

Thank you for your suggestion. Referring to Workbooks(2) did remove the
run-time error, but did not close the workbook.

"K Dales" wrote:

Your trouble is in the line Workbooks("Data.xls").Close False and the problem
seems to be that it does not recognize Data.xls as the workbook name. Check
the name against what appears in the project explorer (VBA editor) when the
book is open. Or refer to it as Workbooks(2).
--
- K Dales


"SusanK521" wrote:

Data.xls is a shared workbook which, when opened, also opens View.xls via the
following:

Private Sub Workbook_Open()
Workbooks.Open Filename:="C:\My Documents\TestBook\View.xls", updateLinks:=0
ActiveWorkbook.UpdateRemoteReferences = False
Workbooks("View.xls").Worksheets("Sheet1").Activat e
Windows("Data.xls").Activate
ActiveWindow.Visible = False
End Sub

Data.xls remains hidden to the user throughout the session.
View.xls has 6 protected worksheets, linked to Data.xls, and is nothing more
than a user interface, allowing the user to input to and sort the information
on Data. xls, all of which is done through macros.

All of the above works fine. The problem I'm having is finding a means of
closing Data.xls when the user closes View. xls.

Currently the following is in View.xls:

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

This results in Run-time error 9 Subscript out of range.

Both workbooks need to close, without saving, when View.xls is closed.
After numerous variations of activating & closing windows, workbooks, etc. I
am at my (admittedly limited) wits end.
Any help would be greatly appreciated.
Susan