Selected date on calendar

Discussion in 'Microsoft Outlook Program Addins' started by Marc Weichhold, Dec 21, 2009.

  1. 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
     
    Marc Weichhold, Dec 21, 2009
    #1
    1. Advertisements

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

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


    "Marc Weichhold" <> wrote in message
    news:...
    > 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
     
    Ken Slovak - [MVP - Outlook], Dec 21, 2009
    #2
    1. Advertisements

  3. 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#.
     
    Marc Weichhold, Dec 22, 2009
    #3
  4. Hello,

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

    Strange...

    Marc
     
    Marc Weichhold, Dec 22, 2009
    #4
  5. 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.

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


    "Marc Weichhold" <> wrote in message
    news:...
    > Hello,
    >
    > one more information. I tried the code from Sue as a VBA macro - and it
    > worked.
    >
    > Strange...
    >
    > Marc
     
    Ken Slovak - [MVP - Outlook], Dec 22, 2009
    #5
  6. 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
     
    Marc Weichhold, Dec 23, 2009
    #6
  7. 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.

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


    "Marc Weichhold" <> wrote in message
    news:...
    > 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
     
    Ken Slovak - [MVP - Outlook], Dec 23, 2009
    #7
  8. 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.
     
    Marc Weichhold, Dec 24, 2009
    #8
  9. 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.

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


    "Marc Weichhold" <> wrote in message
    news:...
    > 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.
     
    Ken Slovak - [MVP - Outlook], Dec 24, 2009
    #9
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil

    Getting Outlook Calendar Date

    Phil, Nov 27, 2003, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    490
    Sue Mosher [MVP]
    Dec 10, 2003
  2. Phil

    Getting the selected day in the Outlook Calendar

    Phil, Dec 1, 2003, in forum: Microsoft Outlook Program Addins
    Replies:
    2
    Views:
    491
  3. Guest

    MS Date and Time Picker Control defaults to today's date

    Guest, Jan 14, 2004, in forum: Microsoft Outlook Program Addins
    Replies:
    0
    Views:
    381
    Guest
    Jan 14, 2004
  4. Alexander Rozhin

    Timespan selected in Calendar

    Alexander Rozhin, Aug 11, 2006, in forum: Microsoft Outlook Program Addins
    Replies:
    1
    Views:
    253
    Sue Mosher [MVP-Outlook]
    Aug 11, 2006
  5. Jeff

    How to find selected day on outlook calendar view during menu popup?

    Jeff, May 1, 2008, in forum: Microsoft Outlook Program Addins
    Replies:
    3
    Views:
    588
    Ken Slovak - [MVP - Outlook]
    May 2, 2008
Loading...

Share This Page