John.McLaughlin
Board Regular
- Joined
- Jul 19, 2011
- Messages
- 169
I have a simple WS to list Items needed, errands to run, etc.
Row 1 is the Task’s .Subject (Title) cell, Rows 2 to X is the running list of info.
I can successfully create all tasks .Subject by reading across Row 1. However, the .Body of each task contains the same data from Column 1, and does not read the new data found under each column heading.
How do I nest(?) my Column For/Next statement to copy the data in the new column?
Thanks in advance!
Row 1 is the Task’s .Subject (Title) cell, Rows 2 to X is the running list of info.
I can successfully create all tasks .Subject by reading across Row 1. However, the .Body of each task contains the same data from Column 1, and does not read the new data found under each column heading.
How do I nest(?) my Column For/Next statement to copy the data in the new column?
Thanks in advance!
Code:
Sub OutlookTasks()
Dim ol As Object, olTask As Object
Dim cc As Range
Dim LastRow As Long
Dim N As Long, r As Long
Dim Sendrng As Range
Set Sendrng = Worksheets("TASKS").Range("A1:A100")
' Create .Body of Task by finding/copy all cells in column with data
' Store data found in strtable to paste in .Body of Task
FirstRow = 1
LastRow = Sendrng.Rows.Count '100
FirstCol = 1
LastCol = Sendrng.Columns.Count
For r = FirstRow To LastRow
For c = FirstCol To LastCol
For Each CELL In Cells(r, c)
strtable = strtable & " " & CELL.Value
Next
Next
strtable = strtable & vbNewLine
Next
Set ol = CreateObject("Outlook.Application")
' Get Column heading data as .Subject title of Tasks
For Each cc In Range("A1", Range("A1").End(xlToRight))
Set olTask = ol.CreateItem(3)
With olTask
.Subject = cc.Value
.Body = strtable
.Save
End With
' Goto next Column heading
Next cc
End Sub