![]() |
Call user form from ThisWorkbook; close file if form closed
Using Office 2003 and Windows XP;
1. Could someone please post an example of a command that could call a sub in a user Form module from the ThisWorkBook module? For example: In THISWORKBOOK: Private Sub Workbook_Open() Call UserForm_Initialize End Sub In FORM MODULE: Public Sub UserForm_Initialize() <other code here Me.Show End Sub 2. Is it possible to code a workbook to close automatically if the user form is closed? If so, how? Many thanks for your assistance. |
Call user form from ThisWorkbook; close file if form closed
PART 1.
Here are some examples: In ThisWorkbook: Private Sub Workbook_Open() UserForm1.Show 'Or whatever your userform is named End Sub --------------------------- In form module: Private Sub UserForm_Initialize() Call Main 'This would be the module with your code in it End Sub PART 2. Copy and paste this into the form module: Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) ThisWorkbook.Close (True) 'This saves all changes and closes the workbook End Sub |
Call user form from ThisWorkbook; close file if form closed
In ThisWorkbook module:
Private Sub ThisWorkbook_Open() Load Userform1 Userform1.Show End Sub In the form module: Private Sub UserForm1_Terminate() ActiveWorkbook.Close False End Sub RBS "XP" wrote in message ... Using Office 2003 and Windows XP; 1. Could someone please post an example of a command that could call a sub in a user Form module from the ThisWorkBook module? For example: In THISWORKBOOK: Private Sub Workbook_Open() Call UserForm_Initialize End Sub In FORM MODULE: Public Sub UserForm_Initialize() <other code here Me.Show End Sub 2. Is it possible to code a workbook to close automatically if the user form is closed? If so, how? Many thanks for your assistance. |
All times are GMT +1. The time now is 02:30 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com