ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   userform freezes (https://www.excelbanter.com/excel-discussion-misc-queries/57127-userform-freezes.html)

flow23

userform freezes
 
first time creating a user form.

BAsically 3 buttons to execute macros.

Private Sub CommandButton1_Click()
data
form.hide
End Sub

Private Sub CommandButton2_Click()
Print1
form.hide

End Sub

Private Sub CommandButton3_Click()
ActiveWorkbook.Close
form.hide

End Sub

Private Sub CommandButton4_Click()

Print2
fom.hide
End Sub

however when I click the first buttion.. it doesnt execute the macro.

2nd and 3rd button are ok.
but it freezes

and exit is perfect



keithl816

userform freezes
 

Hi flow23,

Are you opening the form through a command button on a spreadsheet? If
so put this in your code for the commandbutton.


Code:
--------------------

Private Sub Commandbutton1_Click()
Userform1.Show
End Sub
/CODE]

Change userform number to number you are currently using.

To open a sheet that is hidden, from a commandbutton in the userform place code like this in the appropriate command button.


Code:
--------------------

Private Sub CommandButton1_Click()
If Worksheets("sheet1").Visible = True Then
Worksheets("sheet1").Visible = False
Else
Worksheets("sheet1").Visible = True
End If
End Sub

--------------------



To print the sheet put code like this in your userform for Commandbutton2. Change Sheet # to sheet you are currently using.


Code:
--------------------

Private Sub Commandbutton2_Click()
Application.ScreenUpdating = False
Sheets("Sheet1").Visible = True
Sheets("Sheet1").Select
Range("A1:C10").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$C$10"
ActiveWindow.SelectedSheets.PrintOut copies:=1, collate:=True
Sheets("Sheet1").Visible = False
Application.ScreenUpdating = True

End Sub

--------------------


To close the userform with a command button use code like this for commandbutton3.



Code:
--------------------

Private Sub Commandbutton3_Click()
Unload UserForm1
End Sub


--------------------






hope this helps,

Larry


--
keithl816
------------------------------------------------------------------------
keithl816's Profile: http://www.excelforum.com/member.php...o&userid=21287
View this thread: http://www.excelforum.com/showthread...hreadid=487959



All times are GMT +1. The time now is 08:30 AM.

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