J
James Bond via OfficeKB.com
Hello,
I have for a times ago a treed with the same problem. But the problem is not
solved. Sorry.
Public Function MakeAppointment(strOutlookFolderID As String, strSubject As
String, datDatum As Date, strLocation As String, strBody As String, bolAllDay
As Boolean, Optional strvon As String, Optional strbis As String, Optional
strOutlook As String, Optional strOutlookStorID) As String
5 On Error GoTo Handler
Dim olfolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim olns As Outlook.Namespace
10 Set olApp = CreateObject("Outlook.Application")
15 Set olns = olApp.GetNamespace("MAPI")
20 olns.Logon , , False, False
25 If Nz(strOutlookStorID) = "" Then
30 Set olfolder = olns.GetFolderFromID(strOutlookFolderID)
35 Else
40 Set olfolder = olns.GetFolderFromID(strOutlookFolderID,
strOutlookStorID)
45 End If
50 If Nz(strOutlook) = "" Then
55 Set objAppt = olfolder.Items.Add
60 Else
65 Set objAppt = olns.GetItemFromID(strOutlook, olfolder.StoreID)
70 End If
75 With objAppt
80 .Subject = strSubject
85 If Nz(Trim(strLocation)) <> "" Then
90 .Location = strLocation
95 End If
100 If bolAllDay = False Then
105 .Start = CDate(datDatum & " " & strvon & ":00")
110 .End = CDate(datDatum & " " & strbis & ":00")
115 .AllDayEvent = False
120 Else
125 .Start = datDatum
130 .AllDayEvent = True
135 End If
'recurring appointment
'.IsRecurring
140 .ReminderSet = False
145 .Body = strBody
'.Importance = olImportanceHigh
150 .Save
155 MakeAppointment = .EntryID
160 End With
165 olns.Logoff
170 Set objAppt = Nothing
175 Set olfolder = Nothing
180 Set olns = Nothing
185 Set olApp = Nothing
190 Exit Function
Handler:
195 MsgBox Err.Number & "|" & Err.Description & "|" & Erl()
End Function
Now I get an Error in line 40.
Mainly when Outlook was closed.
Waht can I do. How can I start Outlook per VBA?
Thanks for all ideas.
James
I have for a times ago a treed with the same problem. But the problem is not
solved. Sorry.
Public Function MakeAppointment(strOutlookFolderID As String, strSubject As
String, datDatum As Date, strLocation As String, strBody As String, bolAllDay
As Boolean, Optional strvon As String, Optional strbis As String, Optional
strOutlook As String, Optional strOutlookStorID) As String
5 On Error GoTo Handler
Dim olfolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim olns As Outlook.Namespace
10 Set olApp = CreateObject("Outlook.Application")
15 Set olns = olApp.GetNamespace("MAPI")
20 olns.Logon , , False, False
25 If Nz(strOutlookStorID) = "" Then
30 Set olfolder = olns.GetFolderFromID(strOutlookFolderID)
35 Else
40 Set olfolder = olns.GetFolderFromID(strOutlookFolderID,
strOutlookStorID)
45 End If
50 If Nz(strOutlook) = "" Then
55 Set objAppt = olfolder.Items.Add
60 Else
65 Set objAppt = olns.GetItemFromID(strOutlook, olfolder.StoreID)
70 End If
75 With objAppt
80 .Subject = strSubject
85 If Nz(Trim(strLocation)) <> "" Then
90 .Location = strLocation
95 End If
100 If bolAllDay = False Then
105 .Start = CDate(datDatum & " " & strvon & ":00")
110 .End = CDate(datDatum & " " & strbis & ":00")
115 .AllDayEvent = False
120 Else
125 .Start = datDatum
130 .AllDayEvent = True
135 End If
'recurring appointment
'.IsRecurring
140 .ReminderSet = False
145 .Body = strBody
'.Importance = olImportanceHigh
150 .Save
155 MakeAppointment = .EntryID
160 End With
165 olns.Logoff
170 Set objAppt = Nothing
175 Set olfolder = Nothing
180 Set olns = Nothing
185 Set olApp = Nothing
190 Exit Function
Handler:
195 MsgBox Err.Number & "|" & Err.Description & "|" & Erl()
End Function
Now I get an Error in line 40.
Mainly when Outlook was closed.
Waht can I do. How can I start Outlook per VBA?
Thanks for all ideas.
James