PDA

View Full Version : Solved: Calling Userform procedures from worksheet - Help!



aziztt
09-15-2008, 10:26 AM
Im sure there is a simple solution but been trying for hours. :banghead:

I'll keep it simple. I have a userform that has many command buttons that calls procedure on how to change the user interface of userform. For example:


Private Sub ChangeFormUI()
Userform1.Height = 200
Userform1Button2.Visible = True
Userform1Button3.Visible = True
Userform1Button10.Visible = False
Userform1Button16.Visible = True
End Sub

Private Sub Userform1Button1_Click()
ChangeFormUI
End Sub


In all works perfectly fine when CommandButton "Userform1Button1" is pressed. :thumb

My issue is i created two command buttons on "Sheet1" of worksheet to show my Userform1 in different layout.
I want the first button that loads Userform1 as normal.
Second button to show as though Userform1Button1 in Userform1 was pressed when Userform1 starts.

Ive tried the following on "Sheet1" but doesnt call ChangeFormUI procedure to change UI layout of Userform1


Private Sub CommandButton1_Click()
Userform1.Show
End Sub

Private Sub CommandButton2_Click()
Userform1.Show
Userform1.ChangeFormUI
End Sub


Any ideas? : pray2:

Bob Phillips
09-15-2008, 10:45 AM
Public Sub ChangeFormUI()
Userform1.Height = 200
Userform1Button2.Visible = True
Userform1Button3.Visible = True
Userform1Button10.Visible = False
Userform1Button16.Visible = True
End Sub

Private Sub Userform1Button1_Click()
ChangeFormUI
End Sub




Private Sub CommandButton1_Click()
Userform1.Show
End Sub

Private Sub CommandButton2_Click()
Userform1.ChangeFormUI
Userform1.Show
End Sub

aziztt
09-15-2008, 11:23 AM
does not work ...

it says " Compile error, Method or data memeber not found"

aziztt
09-15-2008, 01:48 PM
commandbutton1 and commandbutton2 are control buttons located on sheet1 to call the userform.

Any ideas?

Bob Phillips
09-15-2008, 01:56 PM
Works for me. Did you change The ChangeUI procedure to Public as I showed you in the first code snippet?

david000
09-16-2008, 12:06 AM
Private Sub CommandButton1_Click()
With UserForm1
.Width = 100
'more code here (buttons)
.Show
End With
End Sub

Private Sub CommandButton2_Click()
With UserForm1
.Width = 200
'more code here...
.Show
End With
End Sub

aziztt
09-16-2008, 06:40 AM
sorry xld didnt notice u put "public", problem solved, i knew there was an easy solution

thanks david000 for a different approach!