Hyperlink Not Working in Outlook via Excel Macro

alexaronson

Active Member
Joined
Sep 30, 2005
Messages
314
Hello and thank you for looking at my question.

I have a macro that creates several files and saves them. A task that I have to do every day is email out a hyperlink to the parties that need to review these files when the files are updated. I want to automate my message when the file is done.

So far I am able to create a new outlook message, enter a To, Subject, and Body text and send the email. However, I can't get the message to display the hyperlink.
Code:
Sub Test()

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next

With OutMail
.To = "Test"
.CC = ""
.BCC = ""
.Subject = "Alert 10 for " & Date & " updated"
.Body = "Alert 10 for " & Date & " updated"
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    "S:\COLLABORATIVE SHARING FOLDER\TeamA\Sales\Reports\Alert 10", _
    TextToDisplay:="Alert 10"

.Display
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

when I try changing
Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    "S:\COLLABORATIVE SHARING FOLDER\TeamA\Sales\Reports\Alert 10", _
    TextToDisplay:="Alert 10"
To
Code:
.Body = ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
    "S:\COLLABORATIVE SHARING FOLDER\TeamA\Sales\Reports\Alert 10", _
    TextToDisplay:="Alert 10"
I get "Complie error: Expecdted: end of statement" at the word of Anchor.

When I Try changing the code to
Code:
.Body = "Alert 10 for " & Date & " updated"
.Body = "S:\COLLABORATIVE SHARING FOLDER\TeamA\Sales\Reports\Alert 10"
The first .Body goes away and is replaced with the second .Body. Also the second .Body is not a hyperlink.

Any suggestions?
 
Andrew,

Can you comment the code line. It is coming up as Alert 10 and I can't see the code for it. The hyperlink works. It takes me to my directory path.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Oh I see. Let's try:

HTML:
    strbody = strbody & "<A href='S:\COLLABORATIVE SHARING FOLDER\TeamA\Sales\Reports\Alert 10'>Alert 10 Link</A>"
 
Upvote 0
Thanks Andrew for redirecting me. The ' ' did the trick and stopped the truncation. Everything now works in the macro, from saving a copy of the original file (or form) in a folder based on fields in the "form" over naming the copy according to some other information from the "form" to sending a mail with a link to that exact file (without attaching a file to the mail).

Best regards
Christian
 
Upvote 0

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

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