MrsAdmin
MrsAdmin

Reputation: 548

VBA Excel to Outlook (2010) - Creating Appointments from Date column with Unique dates only

Info: MS Office 2010
Problem(s) Multiple Outlook Profiles & Multiple Calendars & Same date repeated - I want unique only
From: Excel 2010
To: Outlook 2010

Question:
I want to create a VBA that will run from Excel to Outlook. I want to create appointments (tasks if it's proven to be far more suitable) based on a date column in my sheet.

The core issues are:
+ I have 3 different profiles, I only want the appointments/tasks showing in 1 profile (Admin).
+ I have different calendars, I would prefer the appointment to be in the default.
+ I want to add categories to my appointment/task + I have 10,000 rows of data, the dates repeat (a lot), I want only unique dates.
+ I do not want to have prior dates creating appointments/tasks (if possible).

I run 2 reports:
1st Tuesday of the month, pulls in all the sales data from previous months. 4 days before EOM I run the report a 2nd time looking for late payments, declines or refunds, as well as distributor payouts.

The appointments/tasks are to be set to match the dates in excel, or to save some column space I would be happy to have it written in to the VBA code to set the appointments:
1st Tuesday Month
4 days before EOM

I have got some great starter code, but because mine has a lot of data that needs to be filtered (unique dates only, and current to future dates preferred), I'm not sure what I need amended in my code to make it suitable for my setup.

Ref:
http://www.ozgrid.com/forum/showthread.php?t=18157&p=92262#post92262
http://www.vbaexpress.com/forum/showthread.php?25423-Solved-Excel-generate-calendar-appointments-in-Outlook&s=da1942ccfb8b85e3e7eb74ac4c95ed7d&p=177521&viewfull=1#post177521

My current code
Saved/Created in: Macro enabled spreadsheet, Modules (General, not under the sheet name), Tools/References/Microsoft Office 14.0 Object Library [Checked].

Sub StoreReminders()
Dim appOL As Object
Dim objReminder As Object

Set appOL = GetObject(, "Outlook.application")
Set objReminder = appOL.CreateItem(1) ' olAppointmentItem
Set ws1 = Worksheets("sql all 20131228")

objReminder.Start = ws1.Range("a1") & "10:30"
objReminder.Duration = "05:00"
objReminder.Subject = "EOM Reports #1"
objReminder.ReminderMinutesBeforeStart = 30
objReminder.ReminderSet = True
objReminder.Categories = "Acc - 1st Report"
'Becomes: "Acc - EOM Final" when 2nd appointment runs'
objReminder.BusyStatus = olBusy
objReminder.Save

End Sub  

I am getting an error with some of this, starting with: Set appOL = GetObject(, "Outlook.application")

Any help would be great, I'm cutting & paste code together and I just can't get past the errors.

Thanks in advance :)

UPDATE
I received the following error when I used new code:
Compile Error: User-Defined type not defined

Sub SetAppt()
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Dim MySheet As Worksheet

Set MySheet = Worksheets("sql all 20131228")
Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)

With olApt
    .Start = ws1.Range("n7") + TimeValue("10:30")
    'Time is set to 10:30AM on the date of the reminder'
    .Duration = "05:00"
    .Subject = "EOM Reports #1"
    .Location = "Office"
    .Body = "Start of Month, EOM Reports"
    .BusyStatus = olBusy
    .ReminderMinutesBeforeStart = 60
    .Categories = "Acc - 1st Report"
    'Becomes: "Acc - EOM Final" when 2nd appointment runs'
    .ReminderSet = True
    .Save
End With

Set olApt = Nothing
Set olApp = Nothing

End Sub  

So, still at square one not even basic code is working, so not sure how to include the advanced (Outlook User Profile, Unique only dates etc).

Upvotes: 1

Views: 13316

Answers (1)

Steve Gon
Steve Gon

Reputation: 462

You need to add the proper Reference to the Outlook VBA module.

Go to Tools-->References and choose "Microsoft Outlook vXX Library"

That should fix the problem.

Upvotes: 1

Related Questions