ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Auto Open question (https://www.excelbanter.com/excel-programming/285343-auto-open-question.html)

JVS

Auto Open question
 
I have 2 workbooks, book one has no macro's just a hyperlink to workbook 2.
When workbook 2 opens, I'd like it to minimize and open UserForm1.
The only button (at this time) on the form is a cancel button that sets the
focus back on workbook1 and then closes workbook2.
The code I have below works as long as I do NOT "Auto Open" the UserForm1.

If I auto open the form using module code or Workbook_Open (below)
then when workbook2 closes, the hyperlink in Workbook1 does NOT work.

Can someone tell me how automatically open a form in workbook 2 then
properly exit the form and workbook so that the hyperlink in workbook1 will
still work with out having to exit Excel?

Code from workbook2 "This Workbook" section:
==========================================
Private Sub Workbook_Open()
Windows("Workbook2.xls").WindowState = xlMinimized
Load UserForm1
UserForm1.Show
End Sub

UserForm1 "Cancel" button Code as follows:
==========================================
Private Sub cmdExit_Click()
Workbooks("Workbook2.xls").Close
End Sub

Thanks!
Johnny



Bill Manville

Auto Open question
 
Jvs wrote:
Can someone tell me how automatically open a form in workbook 2 then
properly exit the form and workbook so that the hyperlink in workbook1 will
still work with out having to exit Excel?


I would suggest reducing Workbook_Open to

Private Sub Workbook_Open()
Application.OnTime Now, "ShowTheForm"
End Sub

With, in a standard module

Sub ShowTheForm()
ThisWorkbook.Windows(1).WindowState = xlMinimized
Load UserForm1
UserForm1.Show
End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup


JVS

Auto Open question
 
Thank you very much, it works fine!
Have a happy holiday!

Johnny

"Bill Manville" wrote in message
...
Jvs wrote:
Can someone tell me how automatically open a form in workbook 2 then
properly exit the form and workbook so that the hyperlink in workbook1

will
still work with out having to exit Excel?


I would suggest reducing Workbook_Open to

Private Sub Workbook_Open()
Application.OnTime Now, "ShowTheForm"
End Sub

With, in a standard module

Sub ShowTheForm()
ThisWorkbook.Windows(1).WindowState = xlMinimized
Load UserForm1
UserForm1.Show
End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup





All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com