Hi guys, hoping you can help me out. I'm trying to get the "link" in this code to show as a full working variable hyperlink within the email contents. At the moment it generates the text in the email but I have to hyperlink it manually.
Code is:
Sub createemail()
Dim ol As Outlook.Application
Dim olm As Outlook.MailItem
Dim wd As Word.Application
Dim doc As Word.Document
Set ol = New Outlook.Application
For r = 3 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Set olm = ol.CreateItem(olMailItem)
Set wd = New Word.Application
wd.Visible = True
Set doc = wd.Documents.Open(Cells(1, 4).Value)
With wd.Selection.Find
.Text = "<<date>>"
.Replacement.Text = Sheet1.Cells(r, 2).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<time>>"
.Replacement.Text = Sheet1.Cells(r, 3).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<password>>"
.Replacement.Text = Sheet1.Cells(r, 4).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<link>>"
.Replacement.Text = Sheet1.Cells(r, 13).Value
.Execute Replace:=wdReplaceAll
End With
doc.Content.Copy
With olm
.Display
.To = ""
.Subject = Sheet1.Cells(r, 1)
.CC = Sheet1.Cells(r, 9)
Set Editor = .GetInspector.WordEditor
Editor.Content.Paste
'.Send
End With
Set olm = Nothing
Application.DisplayAlerts = False
doc.Close SaveChanges:=False
Set doc = Nothing
wd.Quit
Set wd = Nothing
Application.DisplayAlerts = True
Next
End Sub
Code is:
Sub createemail()
Dim ol As Outlook.Application
Dim olm As Outlook.MailItem
Dim wd As Word.Application
Dim doc As Word.Document
Set ol = New Outlook.Application
For r = 3 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Set olm = ol.CreateItem(olMailItem)
Set wd = New Word.Application
wd.Visible = True
Set doc = wd.Documents.Open(Cells(1, 4).Value)
With wd.Selection.Find
.Text = "<<date>>"
.Replacement.Text = Sheet1.Cells(r, 2).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<time>>"
.Replacement.Text = Sheet1.Cells(r, 3).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<password>>"
.Replacement.Text = Sheet1.Cells(r, 4).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<link>>"
.Replacement.Text = Sheet1.Cells(r, 13).Value
.Execute Replace:=wdReplaceAll
End With
doc.Content.Copy
With olm
.Display
.To = ""
.Subject = Sheet1.Cells(r, 1)
.CC = Sheet1.Cells(r, 9)
Set Editor = .GetInspector.WordEditor
Editor.Content.Paste
'.Send
End With
Set olm = Nothing
Application.DisplayAlerts = False
doc.Close SaveChanges:=False
Set doc = Nothing
wd.Quit
Set wd = Nothing
Application.DisplayAlerts = True
Next
End Sub