PDA

View Full Version : open form according to active workbook



tommy1234
02-16-2009, 03:24 PM
hello
i recently create a userfrom (vbmodaless) which has a CommandButton that open a new workbook in excel.
the userform show some information for the user so i change its size.
now, i want to change the userform size each time the user switch between the 2 different workbooks (each workbook has different userform size).

Private Sub CommandButton3_Click()
Dim abc As String, def As String
abc = ActiveWorkbook.name 'get current open workbook name
Application.DisplayAlerts = False
Call sammary_show ' do some calculation
' open a new workbook (the name 'short' is a public string variable)
Workbooks.Open short
Windows(abc).Activate 'activate current window
def = Right(short, 17) & ".xls"
Windows(def).Activate ' activate new workbook window


each switch should have different form size (i hide information).
i tried to do this on "workbook window activate" but had no success.
thanks

mdmackillop
02-16-2009, 05:03 PM
The button should contain code to set the reduced form size
Private Sub CommandButton1_Click()
Workbooks("Book2.xls").Activate
Me.Height = 300
End Sub


ThisWorkbook module in Book1 restores the size

Private Sub Workbook_Activate()
UserForm1.Height = 500
End Sub