OnLoad / buttons on worksheet itself

melibeth

New Member
Joined
May 9, 2006
Messages
3
How do I show a user form as soon as my .xls file opens?
How to you put a control button on a worksheet and then assign macros to it?
Does anyone know if you can also do this in Word.

Thanks!!!!!!!!!!!!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,785
Office Version
  1. 365
Platform
  1. Windows
1. In the workbook_open event, which is found in the VBA editor, "This Woorkbook" module, enter the line:
Code:
userform1.show

The whole lot should look thus:

Code:
Private Sub Workbook_Open()
userform1.show
End Sub
.............. in both of these cases substituting the userform1 reference to that of your userform in question.
Now, each time your workbook opens, the code will run, and the useform will be shown.

2. Control button.....
Draw the button onto the worksheet, right click/view code/ and put the lines of code inside the two visible lines.

So, if you want a message box to fire from the button, put the line:

Code:
Msgbox "Hello again melibeth!"
within the two sub lines thus:

Code:
Private Sub CommandButton1_Click()
Msgbox "Hello again melibeth!"
End Sub

When you're done, be sure to come out of design mode with your worksheet before trying the button.

3.Yes, you can do this in Word.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,455
Members
417,025
Latest member
MusterDuster

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top