|
-
Apr 28th, 2011, 02:55 PM
#1
Thread Starter
New Member
Excel: Import Excel Info into Outlook
I want to transfer information that's in an Excel spreadsheet into a calendar in outlook. I've written the code below to create new appointments but the appointments are created in my main calendar. How do I direct them to be written in another calendar named Schedule in my mailbox or into a calendar that is in a public folder. The preferred option would be a public folder with the following tree:
\\Public Folders\All Public Folders\Tech Schedule\
Here is the code that has been written:
Sub AddAppointments()
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myApt = myOutlook.createitem(1)
' Set the appointment properties
myApt.Subject = Cells(r, 1).Value
myApt.Location = Cells(r, 2).Value
myApt.Start = Cells(r, 3).Value
myApt.Duration = Cells(r, 4).Value
' If Busy Status is not specified, default to 2 (Busy)
If Trim(Cells(r, 5).Value) = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Cells(r, 5).Value
End If
If Cells(r, 6).Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Cells(r, 7).Value
myApt.Save
r = r + 1
Loop
End Sub
Thanks in advance for the help!
-
Apr 28th, 2011, 04:54 PM
#2
Re: Excel: Import Excel Info into Outlook
code or highlight tags would be nice
vb Code:
Sub AddAppointments() ' Create the Outlook session Set myOutlook = CreateObject("Outlook.Application") ' Start at row 2 r = 2 Do Until Trim(Cells(r, 1).Value) = "" ' Create the AppointmentItem Set myApt = myOutlook.createitem(1) ' Set the appointment properties myApt.Subject = Cells(r, 1).Value myApt.Location = Cells(r, 2).Value myApt.Start = Cells(r, 3).Value myApt.Duration = Cells(r, 4).Value ' If Busy Status is not specified, default to 2 (Busy) If Trim(Cells(r, 5).Value) = "" Then myApt.BusyStatus = 2 Else myApt.BusyStatus = Cells(r, 5).Value End If If Cells(r, 6).Value > 0 Then myApt.ReminderSet = True myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value Else myApt.ReminderSet = False End If myApt.Body = Cells(r, 7).Value myApt.Save r = r + 1 Loop End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 29th, 2011, 10:55 AM
#3
Thread Starter
New Member
Re: Excel: Import Excel Info into Outlook
I'm just starting out writing VBA so please be patient with me. Let me revise this to code that creates a single appointment. Need to direct creation of this appointment to a calendar that is in a public folder not my current mailbox calendar.
Code:
- Sub AddAppointments()
- ' Create the Outlook session
- Set myOutlook = CreateObject("Outlook.Application")
- ' Create the AppointmentItem
- Set myApt = myOutlook.createitem(1)
- ' Set the appointment properties
- myApt.Subject = "Matt"
- myApt.Location = "Office"
- myApt.Start = "4/27/2011 12:00:00 PM"
- myApt.Duration = "30"
- myApt.BusyStatus = 2
- myApt.ReminderSet = True
- myApt.ReminderMinutesBeforeStart = "0"
- myApt.ReminderSet = False
- myApt.Body = "Meeting With Boss"
- myApt.Save
- End Sub
I appreciate any assistance that you can provide.
-
Apr 29th, 2011, 04:24 PM
#4
Re: Excel: Import Excel Info into Outlook
as i do not have outlook installed, i can not be sure how to get the correct folder object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|