macro to format and export to either .csv or outlook

jeffstu

New Member
Joined
Apr 13, 2013
Messages
6
Hi,

I've been trying to find a way to automate exporting my shifts from work from excel into outlook.

I've been manually typing each shift into outlook calendar and it's just getting tedious.

I've managed to copy the relevant data and manually format and save as a .csv and import.

I also managed to record a macro that providing you copy the relevant data from the main spreadsheet into a new one and delete any black or other not needed rows creates a new sheet with the correct formatting.

again this still quite a bit of manual work

i'm sure there is a way to automate this.
The format of the origional spreadsheet is like this, I've tried to include every possible option that could be in each day.

Week 13

<tbody>
</tbody>
User 1User 2
25/03

<tbody>
</tbody>
Monday08:00-16:0009:00-17:00
26/03

<tbody>
</tbody>
Tuesday10:00-18:0012:00-20:00
27/03

<tbody>
</tbody>
Wednesdayls 08:00-16:00ls 09:00-17:00
28/03

<tbody>
</tbody>
Thursdayls 10:00-18:00ls 12:00-20:00
29/03

<tbody>
</tbody>
Fridayfm 08:00-16:00fm 09:00-17:00
30/03

<tbody>
</tbody>
Saturdayfm 10:00-18:00fm 12:00-20:00
31/03

<tbody>
</tbody>
Sunday
Week 14

<tbody>
</tbody>
User 1User 2
01/04

<tbody>
</tbody>
Mondayzd 08:00-16:00zd 09:00-17:00
02/04

<tbody>
</tbody>
Tuesdayzd 10:00-18:00zd 12:00-20:00
03/04

<tbody>
</tbody>
WednesdayHOLIDAYRESTDAY
04/04

<tbody>
</tbody>
Thursday08:00-16:00 (f)09:00-17:00 (f)
05/04

<tbody>
</tbody>
Friday10:00-18:00 (f)12:00-20:00 (f)
06/04

<tbody>
</tbody>
Saturday
07/04

<tbody>
</tbody>
Sunday

<tbody>
</tbody>

To import into outlook / google calendar via .csv the format needs to be

Code:
[TABLE="width: 430"]
<tbody>[TR]
[TD]Subject-[/TD]
[TD]Start Date-[/TD]
[TD]Start Time-[/TD]
[TD]End Date-[/TD]
[TD]End Time-[/TD]
[TD]Description[/TD]
[/TR]
[TR]
[TD]work -[/TD]
[TD="align: right"]08/04/2013[/TD]
[TD] -08:00[/TD]
[TD="align: right"]08/04/2013[/TD]
[TD] -16:00[/TD]
[TD]Todays Shift[/TD]
[/TR]
</tbody>[/TABLE]


Anyone any ideas how to automate this one?

I've been banging my head on the screen for about a week trying to figure it out.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
we can't access the excel sheet from outside work.
and it can change regularly.

And it makes it easier to have shifts in either outlook or google calendar for planning my life.
 
Upvote 0
If the excel spreadsheet was in the cloud but protected by a password that would solve it...
 
Upvote 0
it's on an internal network inaccessible from the outside world
the spreadsheet i'm getting this data from does more than just display shifts,

It would be handy to have it in the calendar as it sync both outlook and Google calendars to my phone,
so i'f i'm out and about I can quickly find out if any plans are overlapping with work.
 
Upvote 0
by now u might have guessed I do not know the answer - but - if you made a dummy spreadsheet that only read the shift details - and that was a google spreadsheet, - job done..... sorry I cannot help further.
 
Upvote 0
Yeah i figured :)

Do appreciate your suggestions but I do need it to either export directly into outlook calendar or to .csv file.

Only takes a few mins to do manually.

But i've always been of the opinion if it can be done manually then automating can't be that hard.

Till i tried to do this :(
 
Upvote 0
You could add the appointments to your calendar automatically. the code below is a basic framework that you could build on to suit your needs.

It will require a reference to the Microsoft Outlook object library to work.

Code:
Sub AddAppointments()

Dim outApp As Outlook.Application
Dim outCal As Outlook.Folder
Dim outAppt As Outlook.AppointmentItem
Dim sStDate As Date, sEndDate As Date
Dim i As Integer


sStDate = CDate(InputBox("Type Start Date", "Start Date"))
sEndDate = CDate(InputBox("Type End Date", "End Date"))


Set outApp = Outlook.Application
Set outCal = outApp.Session.GetDefaultFolder(olFolderCalendar)


For i = 1 To ActiveSheet.UsedRange.Rows.Count
    If Cells(i, 1) >= sStDate And _
       Cells(i, 1) <= sEndDate And _
       Not Cells(i, 1).Offset(0, 1) = "" Then
        Set outAppt = outCal.Items.Add
        With outAppt
            .Subject = "work"
            .Start = CStr(Cells(i, 1)) + " " + CStr(Format(Cells(i, 3), "hh:mm"))
            .End = CStr(Cells(i, 1)) + " " + CStr(Format(Cells(i, 4), "hh:mm"))
            .Body = "Today's Shift"
            .Save
        End With
    End If
Next i


Set outAppt = Nothing
Set outCal = Nothing
Set outApp = Nothing
End Sub

The code assumes the layout in your post and that the data starts in column A. It uses two input boxes to get a start and an end date in order to avoid checking the calendar each time to make sure you haven't already added the appointment -- so there is still a little manual effort involved - although you can modify the code to remove this.

Hopefully this helps as a place to start.

Simon
 
Upvote 0

Forum statistics

Threads
1,203,174
Messages
6,053,916
Members
444,694
Latest member
JacquiDaly

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top