Selected date on calendar

Status
Not open for further replies.
M

Marc Weichhold

Hello,

I am trying to get the selected date from the calendar month view. I already

learned that the calendar view object itself does not provide any means to

get that data, however, I found Sue Moshers solution on

http://www.outlookcode.com/codedetail.aspx?id=616

Basically, it fetches the command for a new appointment, executes it (so the

new appointment form would open), reads the start and end date from the form

and closes it again. The problem here is that the execute command does not

"work" - there is no new appointment form that opens. No error message, no

exception, just nothing is happening.

Several other readers had that problem, too, and the solution seemed to be

that the command bars had to be reset. But I did not change any command bars

here (no custom commands yet), so I can not reset them.

Can anyone help me?

Marc
 
The command being executed is the New, Appointment command on the Standard

toolbar. Is that being displayed and are you displaying a calendar folder

when you execute your code?

What if you switch the command button and try using 1992 as the button ID to

execute, does that work? That's the Actions, New Appointment button.

"Marc Weichhold" <spam@protect.org> wrote in message

news:unX7C9kgKHA.3888@TK2MSFTNGP02.phx.gbl...
> Hello,

> I am trying to get the selected date from the calendar month view. I
> already learned that the calendar view object itself does not provide any
> means to get that data, however, I found Sue Moshers solution on

> http://www.outlookcode.com/codedetail.aspx?id=616

> Basically, it fetches the command for a new appointment, executes it (so
> the new appointment form would open), reads the start and end date from
> the form and closes it again. The problem here is that the execute command
> does not "work" - there is no new appointment form that opens. No error
> message, no exception, just nothing is happening.

> Several other readers had that problem, too, and the solution seemed to be
> that the command bars had to be reset. But I did not change any command
> bars here (no custom commands yet), so I can not reset them.

> Can anyone help me?

> Marc
 
Hello Ken.


> The command being executed is the New, Appointment command on the Standard
> toolbar. Is that being displayed and are you displaying a calendar folder
> when you execute your code?
>


Yes, I am displaying the calendar month view when the code is executed and

the command (New, Appointment) is displayed on the standard toolbar.


> What if you switch the command button and try using 1992 as the button ID
> to execute, does that work? That's the Actions, New Appointment button.
>


I tried it and the behavior is the same as before. The execute command does

not open the appointment form and I get no error or exception.

The "funny" part is, for testing purposes I changed the caption of the

command right before I call the execute method - and that works. The caption

is changed, but the execute method is still without effect.

Marc

PS: Btw, if that is important, I am using Outlook 2007 with Exchange Server

2007 and a Visual Studio 2008 Developer Edition. The AddIn language is C#.
 
Hello,

one more information. I tried the code from Sue as a VBA macro - and it

worked.

Strange...

Marc
 
Now I'm confused.

The code Sue had up is an Outlook VBA macro. What were you trying it as

previously?

If the code wasn't running inside the Outlook VBA project it would never

work as written, the Application object referenced wouldn't be an

Outlook.Application object.

"Marc Weichhold" <spam@protect.org> wrote in message

news:OqANLgtgKHA.2780@TK2MSFTNGP05.phx.gbl...
> Hello,

> one more information. I tried the code from Sue as a VBA macro - and it
> worked.

> Strange...

> Marc
 
Hello Ken,


> The code Sue had up is an Outlook VBA macro. What were you trying it as
> previously?

> If the code wasn't running inside the Outlook VBA project it would never
> work as written, the Application object referenced wouldn't be an
> Outlook.Application object.
>


I used the code in a VSTO-AddIn written in C#. Of course, I made some

changes so it would compile and run. It is not that hard, after all I GET

the right button. I can read its properties, even change them. All that does

not work - in the C#-AddIn - is the Execute-method.

For C# the code changes to:

// Application is of type Microsoft.Office.Interop.Outlook.Application

Outlook.Explorer objExpl = Application.ActiveExplorer();

if(objExpl != null)

{

Outlook.Folder objFolder = (Outlook.Folder)objExpl.CurrentFolder;

if(objFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)

{

Office.CommandBarButton objCB =

(Office.CommandBarButton)objExpl.CommandBars.FindControl(Type.Missing, 1106,

Type.Missing, Type.Missing);

if(objCB != null)

{

objCB.Execute();

Outlook.AppointmentItem objAppt =

(Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;

DateTime dtStart = objAppt.Start;

DateTime dtEnd = objAppt.End;

((Outlook._AppointmentItem)objAppt).Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);

}

}

}

And as I said, if I place

objCB.Caption = "BlahBlah";

before

objCB.Execute();

then the caption of the button is changed.

Marc
 
If you were to breakpoint on the line:

DateTime dtStart = objAppt.Start;

does an Inspector ever get opened with the appointment?

I just tried your code and it works here with no problems with Outlook 2007

and a VSTO addin written in C#. I fired the code from a button click in an

Explorer window, the code ran from my Explorer wrapper class. About the only

change I made was to just use the class level Explorer object in the wrapper

and not use an Application object to get ActiveExplorer(). Other than that

my code was a copy and paste of yours. So I'm not sure why it's not working

for you.

"Marc Weichhold" <spam@protect.org> wrote in message

news:ukrum86gKHA.2160@TK2MSFTNGP02.phx.gbl...
> Hello Ken,
>
> > The code Sue had up is an Outlook VBA macro. What were you trying it as
> > previously?
>

>> If the code wasn't running inside the Outlook VBA project it would never
> > work as written, the Application object referenced wouldn't be an
> > Outlook.Application object.
> >


> I used the code in a VSTO-AddIn written in C#. Of course, I made some
> changes so it would compile and run. It is not that hard, after all I GET
> the right button. I can read its properties, even change them. All that
> does not work - in the C#-AddIn - is the Execute-method.

> For C# the code changes to:

> // Application is of type Microsoft.Office.Interop.Outlook.Application
> Outlook.Explorer objExpl = Application.ActiveExplorer();
> if(objExpl != null)
> {
> Outlook.Folder objFolder = (Outlook.Folder)objExpl.CurrentFolder;
> if(objFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
> {
> Office.CommandBarButton objCB =
> (Office.CommandBarButton)objExpl.CommandBars.FindControl(Type.Missing,
> 1106, Type.Missing, Type.Missing);
> if(objCB != null)
> {
> objCB.Execute();
> Outlook.AppointmentItem objAppt =
> (Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;
> DateTime dtStart = objAppt.Start;
> DateTime dtEnd = objAppt.End;

> ((Outlook._AppointmentItem)objAppt).Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
> }
> }
> }

> And as I said, if I place

> objCB.Caption = "BlahBlah";

> before

> objCB.Execute();

> then the caption of the button is changed.

> Marc
 
Hello Ken,


> If you were to breakpoint on the line:

> DateTime dtStart = objAppt.Start;

> does an Inspector ever get opened with the appointment?
>


No, there is no Inspector opened at all. The code does throw an exception at

the line

Outlook.AppointmentItem objAppt =

(Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;

because the method ActiveInspector() returns null. And that's why it would

never reach a breakpoint at the line with dtStart. If I understood it right,

the button's Execute-method is supposed to open a new Inspector object

(which then does open the appointment form). But that never happens, so

there is no ActiveInspector at all after the Execute command. The container

Application.Inspectors is also empty at the point (Count = 0).


> I just tried your code and it works here with no problems with Outlook
> 2007 and a VSTO addin written in C#. I fired the code from a button click
> in an Explorer window, the code ran from my Explorer wrapper class. About
> the only change I made was to just use the class level Explorer object in
> the wrapper and not use an Application object to get ActiveExplorer().
> Other than that my code was a copy and paste of yours. So I'm not sure why
> it's not working for you.
>


Beats me, too. From your experience, would you really think that the

Explorer object is the "problem"? I mean, after all I can manipulate the

button object that I get from the Explorer's command bars...

Marc

PS: Happy Holidays.
 
I have no idea what the problem is since the same code worked perfectly

here. I tested it in Outlook 2007, with a VSTO addin written in C# with your

code. That's about as close as I can get to whatever your setup is.

Are you running any Outlook addins at all? I'd disable any that might be

running just on the off chance that some other addin is messing up yours.

But I wouldn't put money on that being the problem.

Happy holidays to you too, and to everyone here.

"Marc Weichhold" <spam@protection.de> wrote in message

news:eYY6HKKhKHA.2188@TK2MSFTNGP04.phx.gbl...
> Hello Ken,
>
> > If you were to breakpoint on the line:
>

>> DateTime dtStart = objAppt.Start;
>

>> does an Inspector ever get opened with the appointment?
> >

> No, there is no Inspector opened at all. The code does throw an exception
> at the line

> Outlook.AppointmentItem objAppt =
> (Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;

> because the method ActiveInspector() returns null. And that's why it would
> never reach a breakpoint at the line with dtStart. If I understood it
> right, the button's Execute-method is supposed to open a new Inspector
> object (which then does open the appointment form). But that never
> happens, so there is no ActiveInspector at all after the Execute command.
> The container Application.Inspectors is also empty at the point (Count =
> 0).
>
> > I just tried your code and it works here with no problems with Outlook
> > 2007 and a VSTO addin written in C#. I fired the code from a button click
> > in an Explorer window, the code ran from my Explorer wrapper class. About
> > the only change I made was to just use the class level Explorer object in
> > the wrapper and not use an Application object to get ActiveExplorer().
> > Other than that my code was a copy and paste of yours. So I'm not sure
> > why it's not working for you.
> >

> Beats me, too. From your experience, would you really think that the
> Explorer object is the "problem"? I mean, after all I can manipulate the
> button object that I get from the Explorer's command bars...

> Marc

> PS: Happy Holidays.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S Printing Selected Date Range in Monthly Style Using Outlook 1
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
Witzker Add a text line at the end of the note field in all selected Contacts Outlook VBA and Custom Forms 7
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
N Save selected messages VBA does not save replies and/or messages that contain : in subject Outlook VBA and Custom Forms 1
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
B Change row background color of selected item Using Outlook 1
T Change the selected Message in the Outlook window Outlook VBA and Custom Forms 2
H Custom Signature Not Displayed When Account Selected Outlook VBA and Custom Forms 10
J Checkboxes when selected will appear in a textbox in Outlook 2016 Outlook VBA and Custom Forms 1
K How to reference the selected folder Outlook VBA and Custom Forms 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
P Outlook 2013 opens with FILE tab selected. Using Outlook 3
C Change Subject Line in Selected Emails Outlook VBA and Custom Forms 1
G Autocomplete adds suspicious "@unknown.email" to selected contacts Using Outlook 1
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
M code to move selected Outlook contacts to another folder Using Outlook 3
A Helping OL remember which calendars were selected Using Outlook 6
Diane Poremsky Save Selected Email Message as .msg File Using Outlook 11
D Delete selected text from incoming emails Outlook VBA and Custom Forms 25
mikolajek Random message selected after hard delete Using Outlook 4
Diane Poremsky Working with All Items in a Folder or Selected Items Using Outlook 0
Diane Poremsky Outlook VBA: Work with Open Item or Selected Item Using Outlook 0
A VBA to create meeting from template from a time slot selected in someone's calendar Outlook VBA and Custom Forms 5
Diane Poremsky Create Task or Appointment and Insert Selected Text Using Outlook 0
Yusufbodrum Highlighting selected mails in any folder Using Outlook 2
P Subject change on selected emails Outlook VBA and Custom Forms 14
C Autofill subject line in appointment from options selected in combobox Using Outlook 6
P Is it possible to write a macro to email to all addresses of selected contacts? Using Outlook 1
M Save selected email message as .msg file (with user to choose folder location) Outlook VBA and Custom Forms 14
S Macro to print & move selected emails? Using Outlook 3
L Selected Contacts For E-Mails Using Outlook 19
K Help! I selected every contact and mistakenly made them all the same category Using Outlook 1
C Outlook 2010 Address Book, won't stay selected Using Outlook 5
L Outlook 2007 E-Mail From Selected Task Using Outlook 18
L Email For Selected Contacts Using Outlook 5
D Trigger macro to run when selected email is opened Using Outlook 3
D Launch Outlook showing only selected messages. Using Outlook 1
J Capturing forward event when multiple items are selected Using Outlook 0
P Export selected contacts to a .csv Using Outlook 2

Similar threads

Back
Top