LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Need code to close minimized workbooks in BeforeClose event

I've written code to open a workbook and set path and file name variables
based on values in named ranges of the open workbook. I then use these
variables to open three additional workbooks and minimize them. All that is
working fine. However, I need to close the three minimized workbooks when I
close the main workbook, I presume in the BeforeClose event. I can't seem to
figure out how to do this. I tried setting public variables for the 3
workbooks, but that's not working either. I'm a novice, obviously. Can anyone
supply the code to accomplish this task?

Here's the code I've written to open the 3 supporting workbooks:

Public Wbk1 As Workbook
Public Wbk2 As Workbook
Public Wbk3 As Workbook


Private Sub Workbook_Open()

Application.ScreenUpdating = False

Dim Pname1 As String, Pname2 As String, Pname3 As String
Dim Fname1 As String, Fname2 As String, Fname3 As String
Dim Bk1 As String, Bk2 As String, Bk3 As String

Worksheets("Display").Activate

Pname1 = Worksheets("Display").Range("Path1")
Fname1 = Worksheets("Display").Range("File1")
Pname2 = Worksheets("Display").Range("Path2")
Fname2 = Worksheets("Display").Range("File2")
Pname3 = Worksheets("Display").Range("Path3")
Fname3 = Worksheets("Display").Range("File3")

Bk1 = Pname1 + "\" + Fname1
Bk2 = Pname2 + "\" + Fname2
Bk3 = Pname3 + "\" + Fname3

Workbooks.Open (Bk1)
Set Wbk1 = ActiveWorkbook
ActiveWindow.WindowState = xlMinimized
Workbooks.Open (Bk2)
Set Wbk2 = ActiveWorkbook
ActiveWindow.WindowState = xlMinimized
Workbooks.Open (Bk3)
Set Wbk3 = ActiveWorkbook
ActiveWindow.WindowState = xlMinimized

ActiveWindow.WindowState = xlMaximized
Worksheets("Display").Range("A24").Activate

End Sub

Thanks for any help!

Cheryl

 
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
BeforeClose event help [email protected] Excel Programming 3 June 22nd 07 10:02 AM
BeforeClose Event JT Excel Programming 2 April 10th 07 03:52 PM
VBA Code req to close all workbooks Neil Atkinson Excel Programming 2 September 23rd 05 01:46 PM
VBA Code req to close all workbooks Neil Atkinson Excel Programming 0 September 23rd 05 11:06 AM
File won't close when "beforeclose" event is used. David G[_3_] Excel Programming 4 December 8th 03 04:22 AM


All times are GMT +1. The time now is 12:41 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"