View Single Post
  #4  
Old July 1st 09, 01:11 AM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Changing calendar views

To add any macro to a toolbar as a button select View, Toolbars, Customize.
Select the macro from the Commands list and drag it to the toolbar. A macro
is a Public Sub in an Outlook code module or in ThisOutlookSession.

I'll leave it to you to make the other macros for different time periods,
and also to add error handling and checking for things like each object not
being Nothing. Here's a macro that will move 4 weeks in the future. Note
that Work Week is from a button click, not directly from setting a specific
view.

Sub ViewChange()
Dim exp As Outlook.Explorer
Dim folder As Outlook.MAPIFolder
Dim button As Office.CommandBarButton

Dim dat As Date

Set exp = Application.ActiveExplorer

Set folder = exp.CurrentFolder

' set view
exp.CurrentView = "Day/Week/Month"

' set Work Week "view"
Set button = exp.CommandBars.Item("Standard").FindControl(id:=5 556,
Recursive:=True)
button.Execute

' go to 4 weeks from now
dat = DateAdd("d", 28, Date)
exp.CurrentView.GoToDate dat

Set exp = Nothing
Set folder = Nothing
Set button = Nothing
End Sub

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Douglas Quaid" wrote in message
news

Outlook 2003 SP3
'Ken Slovak - [MVP - Outlook Wrote:
;312287']Outlook version?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Douglas Quaid" wrote in
message
news
Hi, I am new to Outlook and just getting my feet wet on the VB
commands
for it, so I thought I would start with something simple but even
this
little task is eluding me. I prefer to have my calendar view set to
"one day" for today, but all day long I need to set appointments one
month out, and I like to view the calendar one month out in Work Week
view. I would like to create one button I can click that will
automatically shift the view four weeks into the future and switch
the
view to "Work Week," and another button that will take me back to
today
and switch the view to "one day."

Also, I would like to make a button that shifts the view forward one
week, and another that shifts the view backwards one week. I would
put
all these buttons on a custom toolbar so I could navigate around the
calendar easily.

Any help would be greatly appreciated.




--
Douglas Quaid -





--
Douglas Quaid


Ads