Delay When Creating Outlook Appointments

M

msrado

Hello all,

I've created an Outlook add-in using Visual Basic 6 that contains a
class module that can be called by a VB EXE. The class module contains
a routine to create an appointment in Outlook and save it. The EXE
accesses the routine by creating an instance of Outlook with
CreateObject (invisible) and pulling out a reference to the class.
Then it creates the appointment by filling the properties of a new
AppointmentItem object and using the Save method.

The problem is that the appointment doesn't show up in Outlook until a
new appointment is set with a visible version of Outlook. The visible
version of Outlook is created by having the user start Outlook before
the EXE runs or by using the OpenProcess function to open Outlook.

Does anybody know whats going on? I've tried always using OpenProcess
to start Outlook before my EXE gets to the appointment part, but
Outlook always appears maximized with focus and covers my app. Can I
start Outlook through my EXE as a minimized app without focus?

My code for the EXE is :

Dim objOL As Object 'object to text for Outlook
Dim clsAppt as Object 'class to set appointment

'test for outlook
Set objOL = GetObject(, "Outlook.Application")

If objOL Is Nothing Or Err.Number <> 0 Then
Err.Clear
Set objOL = CreateObject("Outlook.Application")
End If

'attach to the class
Set objAddin = objOL.COMAddIns.Item("MyAddIn.Connect").object
If Not (objAddin Is Nothing) Then
Set clsAppt = objAddin.clsAppt
Else
GoTo Trap_Error
End If
Exit Sub

My code in the class is: (objOutlook is created and initialized to the
Outlook Application when the add-in is started)

Dim objAppt As Object 'appointment

On Error GoTo Add_Err

Set objAppt = objOutlook.CreateItem(olAppointmentItem)

With objAppt
.Start = dtStartTime
.End = dtEndTime
.Subject = sSubject
.Location = sLocation
.Body = sBody
.ReminderSet = True
.MeetingStatus = olNonMeeting
.Save
.Close (olSave)
End With

'Release the object variables
Set objAppt = Nothing

I appreciate any help! My app would be super cool if I could figure
this out!

Thanks,
Robin
 
M

Michael Bauer

Am 31 Aug 2005 14:54:05 -0700 schrieb (e-mail address removed):

Not sure if this is the point of your question: If you want OL to be visible
after calling CreateObject then add an Explorer object. The Explorer has a
WindowState property.
 
M

msrado

Hi Michael,

I actually have the opposite problem. I want my app to retain the
focus. I can't get Outlook to go invisible (or minimize) if I Shell to
it. When I use CreateObject and Outlook is invisible (preferred), I
can't get the appointments I create to appear when Outlook is opened by
the user at a later time.

Thanks,
Robin
 
M

Michael Bauer

Am 1 Sep 2005 10:15:33 -0700 schrieb (e-mail address removed):

Robin, now I understand. You can´t see any AppointmentItem because it never
was created. Remove your "On Error Resume Next" statement and you will see
what´s going on.

You can use the sample, just call GetApplication. You can use the variable
m_bAppCreated to determine whether you app has started OL or not. This is
important if your app starts an invisible Outlook: Then you need to close
the created Explorer by code else OL would stay alive.


Private Application As Outlook.Application
Private m_bAppCreated As Boolean

Private Sub GetApplication()
On Error Resume Next
Set Application = GetObject(, "outlook.application")
If Err.Number Then
LogOn_ViaOOM "[YourProfile]", False
Else
m_bAppCreated = False
End If
End Sub

Private Sub LogOn_ViaOOM(sProfile as String, _
Optional ByVal bVisible As Boolean = True _
)
Dim oSess As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder
Dim oExpl As Outlook.Explorer

Set Application = New Outlook.Application
Set oSess = Application.GetNamespace("mapi")
oSess.LogOn sProfile, , False, True

Set oFld = oSess.GetDefaultFolder(olFolderInbox)
Set oExpl = Application.Explorers.Add(oFld)
m_bAppCreated = True

If bVisible Then
oExpl.Display
End If
End Sub
 
M

msrado

Hi Michael,

You know, logging in makes perfect sense now that you mention it. I
should have caught it!

Many thanks for the code!

Regards,
Robin

Michael said:
Am 1 Sep 2005 10:15:33 -0700 schrieb (e-mail address removed):

Robin, now I understand. You can´t see any AppointmentItem because it never
was created. Remove your "On Error Resume Next" statement and you will see
what´s going on.

You can use the sample, just call GetApplication. You can use the variable
m_bAppCreated to determine whether you app has started OL or not. This is
important if your app starts an invisible Outlook: Then you need to close
the created Explorer by code else OL would stay alive.


Private Application As Outlook.Application
Private m_bAppCreated As Boolean

Private Sub GetApplication()
On Error Resume Next
Set Application = GetObject(, "outlook.application")
If Err.Number Then
LogOn_ViaOOM "[YourProfile]", False
Else
m_bAppCreated = False
End If
End Sub

Private Sub LogOn_ViaOOM(sProfile as String, _
Optional ByVal bVisible As Boolean = True _
)
Dim oSess As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder
Dim oExpl As Outlook.Explorer

Set Application = New Outlook.Application
Set oSess = Application.GetNamespace("mapi")
oSess.LogOn sProfile, , False, True

Set oFld = oSess.GetDefaultFolder(olFolderInbox)
Set oExpl = Application.Explorers.Add(oFld)
m_bAppCreated = True

If bVisible Then
oExpl.Display
End If
End Sub

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Hi Michael,

I actually have the opposite problem. I want my app to retain the
focus. I can't get Outlook to go invisible (or minimize) if I Shell to
it. When I use CreateObject and Outlook is invisible (preferred), I
can't get the appointments I create to appear when Outlook is opened by
the user at a later time.

Thanks,
Robin
 
M

msrado

Hi again,

The login didn't do the trick. It turned out that I had to specify
that the appointment was going onto the user's calendar by putting "Set
objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar)" just
above the line where I create the appointment.

Regards,
Robin

Hi Michael,

You know, logging in makes perfect sense now that you mention it. I
should have caught it!

Many thanks for the code!

Regards,
Robin

Michael said:
Am 1 Sep 2005 10:15:33 -0700 schrieb (e-mail address removed):

Robin, now I understand. You can´t see any AppointmentItem because itnever
was created. Remove your "On Error Resume Next" statement and you will see
what´s going on.

You can use the sample, just call GetApplication. You can use the variable
m_bAppCreated to determine whether you app has started OL or not. This is
important if your app starts an invisible Outlook: Then you need to close
the created Explorer by code else OL would stay alive.


Private Application As Outlook.Application
Private m_bAppCreated As Boolean

Private Sub GetApplication()
On Error Resume Next
Set Application = GetObject(, "outlook.application")
If Err.Number Then
LogOn_ViaOOM "[YourProfile]", False
Else
m_bAppCreated = False
End If
End Sub

Private Sub LogOn_ViaOOM(sProfile as String, _
Optional ByVal bVisible As Boolean = True _
)
Dim oSess As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder
Dim oExpl As Outlook.Explorer

Set Application = New Outlook.Application
Set oSess = Application.GetNamespace("mapi")
oSess.LogOn sProfile, , False, True

Set oFld = oSess.GetDefaultFolder(olFolderInbox)
Set oExpl = Application.Explorers.Add(oFld)
m_bAppCreated = True

If bVisible Then
oExpl.Display
End If
End Sub

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Hi Michael,

I actually have the opposite problem. I want my app to retain the
focus. I can't get Outlook to go invisible (or minimize) if I Shell to
it. When I use CreateObject and Outlook is invisible (preferred), I
can't get the appointments I create to appear when Outlook is opened by
the user at a later time.

Thanks,
Robin

Michael Bauer wrote:
Am 31 Aug 2005 14:54:05 -0700 schrieb (e-mail address removed):

Not sure if this is the point of your question: If you want OL to be visible
after calling CreateObject then add an Explorer object. The Explorerhas a
WindowState property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

Hello all,

I've created an Outlook add-in using Visual Basic 6 that contains a
class module that can be called by a VB EXE. The class module contains
a routine to create an appointment in Outlook and save it. The EXE
accesses the routine by creating an instance of Outlook with
CreateObject (invisible) and pulling out a reference to the class.
Then it creates the appointment by filling the properties of a new
AppointmentItem object and using the Save method.

The problem is that the appointment doesn't show up in Outlook until a
new appointment is set with a visible version of Outlook. The visible
version of Outlook is created by having the user start Outlook before
the EXE runs or by using the OpenProcess function to open Outlook.

Does anybody know whats going on? I've tried always using OpenProcess
to start Outlook before my EXE gets to the appointment part, but
Outlook always appears maximized with focus and covers my app. CanI
start Outlook through my EXE as a minimized app without focus?

My code for the EXE is :

Dim objOL As Object 'object to text for Outlook
Dim clsAppt as Object 'class to set appointment

'test for outlook
Set objOL = GetObject(, "Outlook.Application")

If objOL Is Nothing Or Err.Number <> 0 Then
Err.Clear
Set objOL = CreateObject("Outlook.Application")
End If

'attach to the class
Set objAddin = objOL.COMAddIns.Item("MyAddIn.Connect").object
If Not (objAddin Is Nothing) Then
Set clsAppt = objAddin.clsAppt
Else
GoTo Trap_Error
End If
Exit Sub

My code in the class is: (objOutlook is created and initialized to the
Outlook Application when the add-in is started)

Dim objAppt As Object 'appointment

On Error GoTo Add_Err

Set objAppt = objOutlook.CreateItem(olAppointmentItem)

With objAppt
.Start = dtStartTime
.End = dtEndTime
.Subject = sSubject
.Location = sLocation
.Body = sBody
.ReminderSet = True
.MeetingStatus = olNonMeeting
.Save
.Close (olSave)
End With

'Release the object variables
Set objAppt = Nothing

I appreciate any help! My app would be super cool if I could figure
this out!

Thanks,
Robin
 

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