Hi all - I am very new to using Macros with Excel and I am looking for help. I am using code to attempt to automatically generate a word doc with upcoming deadlines/due dates in my Excel sheet. Currently, it will only generate a word doc if I manually run the code. Also, I am having trouble getting the task description (Column N) generate automatically in my word doc report (Column N should correspond with Columns K-M). I hope someone can please help me. Here's the code I am using:
Sub Due_Date()
Dim DueDate_Col As Range
Dim Due As Range
Dim PopUp_Notification As String
Set DueDate_Col = Range("J2:J500,D2:D500,D2:D500,M2:M500")
For Each Due In DueDate_Col
If Due <> "" And Date >= Due - Range("S2") Then
PopUp_Notification = PopUp_Notification & vbCrLf & Cells(Due.Row, "A") & " - " & Cells(1, Due.Column) & " - " & Due.Value
End If
Next Due
If PopUp_Notification = "" Then
MsgBox "No outstanding tasks/SOLs due."
Else
Dim WordApp As Object
Dim WDoc As Object
'
'Create Word.Application
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
Err.Clear
End If
On Error GoTo 0
WordApp.Visible = True
Set WDoc = WordApp.Documents.Add
WDoc.Range(0, 0).Text = PopUp_Notification
WordApp.Activate
End If
End Sub
Sub Due_Date()
Dim DueDate_Col As Range
Dim Due As Range
Dim PopUp_Notification As String
Set DueDate_Col = Range("J2:J500,D2:D500,D2:D500,M2:M500")
For Each Due In DueDate_Col
If Due <> "" And Date >= Due - Range("S2") Then
PopUp_Notification = PopUp_Notification & vbCrLf & Cells(Due.Row, "A") & " - " & Cells(1, Due.Column) & " - " & Due.Value
End If
Next Due
If PopUp_Notification = "" Then
MsgBox "No outstanding tasks/SOLs due."
Else
Dim WordApp As Object
Dim WDoc As Object
'
'Create Word.Application
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
Err.Clear
End If
On Error GoTo 0
WordApp.Visible = True
Set WDoc = WordApp.Documents.Add
WDoc.Range(0, 0).Text = PopUp_Notification
WordApp.Activate
End If
End Sub