Command Button + VBA Code to open Outlook calendar?

mrkris1982

Active Member
Joined
Apr 16, 2009
Messages
407
I'd like to create a command button within excel with VBA code linking it to a shared Outlook calendar. In theory, when you click on this button, it would open the shared calendar.

Any ideas on if/how this can be accomplished?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
in the event it matters, the functional mailbox is called OpsAdmin.....or within active directory its F_OpsAdmin
 
Upvote 0
Code:
Sub ShowSharedCalendar()
  Dim recip As Outlook.Recipient
  Dim calfolder As Outlook.MAPIFolder
  ' create shared recipient
  Set recip = session.CreateRecipient("OpsAdmin")
  ' reference to shared calendar
  Set calfolder = session.GetSharedDefaultFolder(recip, olFolderCalendar)
  calfolder.Display
End Subp
 
Upvote 0
I created the command button and pasted the code (althought i think subp should be sub at the end, right?)

I did it exactly with what you have and the following way. Both flag a compile error: Expected End Sub

Code:
Private Sub CommandButton1_Click()
Sub ShowSharedCalendar()
  Dim recip As Outlook.Recipient
  Dim calfolder As Outlook.MAPIFolder
  ' create shared recipient
  Set recip = Session.CreateRecipient("OpsAdmin")
  ' reference to shared calendar
  Set calfolder = Session.GetSharedDefaultFolder(recip, olFolderCalendar)
  calfolder.Display
End Sub
 
Upvote 0
Yes, it should be "End Sub", no idea how that happened.

Did you get the error BEFORE removing the "p"? That error will occur if there is a typo.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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