run macro when sheet opens

kavanagh

Board Regular
Joined
Apr 1, 2009
Messages
155
I have a monthview calender that opens with a created macro button
but I'd like it to open the calender when a worksheet opens without having to use my macro button.
any help would be appreaciated

Thank you in advance. K

heres the code i have



Private Sub CMDCLOSE_Click()
Unload Me
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
ActiveCell.Value = MonthView1.Value
Unload Me
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
Range("l4").Select
If IsDate(ActiveCell.Value) Then
MonthView1.Value = DateValue(ActiveCell.Value)
Else
MonthView1.Value = Date

End If
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
worksheet opens???
Do you mean when you select or activate the worksheet? If yes...

  • Right-click on the worksheet tab that you want this to work on.
  • Select View Code from the pop-up menu
  • Paste the code below in the VBA edit window.

Code:
Private Sub Worksheet_Activate()
    UserForm1.Show
End Sub

UserForm1 is the name of your calendar form.
 
Upvote 0
In thisworkbook module paste below code
Code:
Private Sub Workbook_Open()
Me.Show
End Sub
 
Upvote 0
Thanks Guys but I just can't seem to get it to work

When I put it in the worksheet tab nothing happens
I get a run time error 424 and object required



When I put it in the workbook Module nothing happens and it gives me a compile error in hidden module.

I need to work on it a bit I'm not that proficient at this

Thank you k
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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
Back
Top