Changing calendar views

D

Douglas Quaid

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.
 
D

Douglas Quaid

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




"Douglas Quaid" (e-mail address removed) wrote in
message

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.
 
K

Ken Slovak - [MVP - Outlook]

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:=5556,
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




Douglas Quaid said:
Outlook 2003 SP3
'Ken Slovak - [MVP - Outlook said:
;312287']Outlook version?




"Douglas Quaid" (e-mail address removed) wrote in
message

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.
 
D

Douglas Quaid

Thanks, Ken, this is good stuff. The one thing that worked a little
better for me was replacing "Date" with "Now" in the DateAdd code.
With "Date" it was going to 12 AM and then I would have to scroll down.
With "Now" it goes to the current time, which is perfect for me.

The only problem I still have is jumping forward or backward a week
from the currently selected date, as opposed to today's date. If you
could point me in the right direction for that I would really
appreciate it.
 
K

Ken Slovak - [MVP - Outlook]

The key is the DateAdd() function. Change 28 days to 7 and you jump a week.
Change it to -28 and you jump back 4 weeks from today. Make a new macro for
each different date jump you want and name them appropriately.

For more on DateAdd() use the help.
 
D

Douglas Quaid

Ken, I really appreciate your time. I don't think I explained what I am
trying to do well enough. I understand the DateAdd() function. What I
need to do, though, is to jump a week forward or back from the
Currently Selected Date. Not a week forward or back from Today. Does
that make sense?

The DateAdd() help only tells you how to jump from today, or from a
specific date. I need a command to return a string with whatever date
I'm currently looking at to fill in that last variable in the DateAdd
function.

'Ken Slovak - [MVP - Outlook said:
;312707']The key is the DateAdd() function. Change 28 days to 7 and you
jump a week.
Change it to -28 and you jump back 4 weeks from today. Make a new macro
for
each different date jump you want and name them appropriately.

For more on DateAdd() use the help.
 
K

Ken Slovak - [MVP - Outlook]

No way to do that in Outlook 2003. That's not exposed to the object model.

In Outlook 2007 you could use the new CalendarView.DisplayedDates property
to let you know which dates were currently visible in the UI.
 
D

Douglas Quaid

OK, thanks for your help Ken. One last thing- is there a list of all
the button IDs somewhere online (for example, Work Week View is 5556)?


'Ken Slovak - [MVP - Outlook said:
;312932']No way to do that in Outlook 2003. That's not exposed to the
object model.

In Outlook 2007 you could use the new CalendarView.DisplayedDate
property
to let you know which dates were currently visible in the UI.




"Douglas Quaid" (e-mail address removed) wrote i
message

Ken, I really appreciate your time. I don't think I explained what
am
trying to do well enough. I understand the DateAdd() function. Wha
I
need to do, though, is to jump a week forward or back from the
Currently Selected Date. Not a week forward or back from Today.
Does
that make sense?

The DateAdd() help only tells you how to jump from today, or from a
specific date. I need a command to return a string with whateve
date
I'm currently looking at to fill in that last variable in the DateAdd
function.
 
K

Ken Slovak - [MVP - Outlook]

There are some at various places at www.outlookcode.com, but it's nothing
like a comprehensive list.

What I usually do is use OutlookSpy (www.dimastr.com) for that. I also use
it to get property tags for various MAPI properties. Anyway, that's how I
got the ID for that button for you. With OutlookSpy you select the Explorer
or Inspector button as appropriate and in the window that opens there's a
CommandBars tab. In that you select the relevant toolbar/menu and you'll see
a list of every button in that toolbar/menu.

For ribbon controls you set up to customize the QAT and each control's idMso
is then listed when you hover over the command. The idMso's are also listed
in the downloads for the ribbon schemas from Office Online.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top