View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
external usenet poster
 
Posts: 599
Default Macro for Excel / Outlook

Cormorin

See comments in line

Sub SidewearTask()

Dim olApp As Outlook.Application
Dim olTsk As TaskItem
Dim cell As Range
'Dim olRec As Outlook.RecurrancePattern

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
Body = Range("B6") & " " & Range("C6") & " " & Range("M6") & "
" & Range("E6") & "M" & Range("F6") & "CH" & " " & Range("G6") & "M" &
Range("H6") & "CH"
Subject = "Sidewear Inspection"
DueDate = Range("K6")
'Set olRec = Range("J6")
'.Set olRec = .GetRecurrancePattern
Save
End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub


About how many rows are there? I'm trying to understand what you have and
what you want. Do you want to make a task for every row on a sheet? Does
each task recur, or is the whole sheet one task and each row shows when the
one task recurs?


Two main issues:
1) Not sure how to set the recurrance as I do not understand the .
olrec line. Also the column with the recurrance (col. J) is as follows
24M for 2yearly 12M for yearly etc..


If you want a task to recur, you use GetRecurrancePattern to create a new,
empty recurrance pattern object. Then you can work with olRec to set it up
the way you want

With olTsk
Set olRec = .GetRecurrancePattern
With olRec
.RecurranceType = olRecursMonthly
.Duration = 1
End With
End With

This sets the task to recur on the same day every 1 months. If the DueDate
was today, it would recur on the 6th day of every month.

Post a small sample of what kind of data is in your columns and how that
data relates to how often the task should recur.


2) If I have to create the above for each record it will take nearly as
long as creating all the tasks manually. Is there a way to do it in a
loop to same repaet until record in column B is blank ie the end of the
work sheet ?


Everything you have so far and anything you add can go in a loop. I would
use a For Each loop to loop through the cells in column B. Then use the
Offset property to get to the column you want to use.

Dim Rng As Range
Dim cell As Range

Set Rng = Sheet1.Range("B6",Sheet1.Range("B6").End(xlDown))

For Each Cell in Rng.Cells
Set olTsk = olApp.CreateItem(olTaskItem)
With olTsk
'Set task properties
.Body = cell.Value & " " & cell.Offset(0,1).Value & " " &
cell.Offset(0,11).Value
.Subject = cell.Parent.Name
'etc...
End With
Next Cell

The Set Rng line uses the End property to determine the range. It would be
like selecting B6 and using Shift+End+Down arrow to extend the range to the
next blank line.


3) the subject box should read the same as the tab (sheet name)


This is why asked if each row was a separate task or the whole sheet is one
task. If the the former, do you want all the tasks to have the same
subject? In the above code fragment, I used cell.Parent.Name to get the
name of the sheet. Once we clear up what each row on the sheet represents
and how the data in each row relates to the recurrance pattern, it should be
straight forward as to how to do this automatically, that is, so the macro
is considerably easier than doing it manually.


--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com