Error with Sending Hyperlink via email using VBA

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hi,

I keep getting Compile Syntax Error when trying to run the following Macro. Please Help!

VBA Code:
Sub Give_Feedback()

Dim EmailApp As Object
Dim EmailItem3 As Object
Dim xStrBody As String
xStrBody = "Good Morning/Afternoon" & "<br>" & "<br>" _
& "My feedback is about:" & "<br>" & "<br>" & "Kind regards," & "<br>" _
& "Insert Name Here" & "<br>" & "<br>" & _
"Do You want to receive a free month for your subscription? Fill out our survey by clicking "<a href=""https://4screens.net/e/62b1566495602c01000005c6"">Here</a> "

 On Error Resume Next
   
Set EmailApp = CreateObject("Outlook.Application")
Set EmailItem3 = EmailApp.CreateItem(0)


With EmailItem3

.To = ""

.Subject = "Feedback"

.HTMLBody = .HTMLBody & xStrBody


.Display

End With
Set EmailItem3 = Nothing
Set EmailApp = Nothing


End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,

I keep getting Compile Syntax Error when trying to run the following Macro. Please Help!

VBA Code:
Sub Give_Feedback()

Dim EmailApp As Object
Dim EmailItem3 As Object
Dim xStrBody As String
xStrBody = "Good Morning/Afternoon" & "<br>" & "<br>" _
& "My feedback is about:" & "<br>" & "<br>" & "Kind regards," & "<br>" _
& "Insert Name Here" & "<br>" & "<br>" & _
"Do You want to receive a free month for your subscription? Fill out our survey by clicking "<a href=""https://4screens.net/e/62b1566495602c01000005c6"">Here</a> "

 On Error Resume Next
  
Set EmailApp = CreateObject("Outlook.Application")
Set EmailItem3 = EmailApp.CreateItem(0)


With EmailItem3

.To = ""

.Subject = "Feedback"

.HTMLBody = .HTMLBody & xStrBody


.Display

End With
Set EmailItem3 = Nothing
Set EmailApp = Nothing


End Sub
make following change:

& "Do You want to receive a free month for your subscription? Fill out our survey by clicking <a href=" & "https://4screens.net/e/62b1566495602c01000005c6" & ">Here</a> "
 
Upvote 0
1659507955010.png
 
Upvote 0
Thanks! This fixed the Syntax Error.

But now I am getting the "expect, end of statement error" at the href part. I tried to change the code exactly as you suggested.

VBA Code:
Sub Give_Feedback()

Dim EmailApp As Object
Dim EmailItem3 As Object
Dim xStrBody As String
xStrBody = "Good Morning/Afternoon" & "<br>" & "<br>" _
& "My feedback is about:" & "<br>" & "<br>" & "Kind regards," & "<br>" _
& "Insert Name Here" & "<br>" & "<br>" _
& "Do You want to receive a free month for your subscription? Fill out our survey by clicking "<a href=" & "https://4screens.net/e/62b1566495602c01000005c6" & ">Here</a> "

 On Error Resume Next
  
Set EmailApp = CreateObject("Outlook.Application")
Set EmailItem3 = EmailApp.CreateItem(0)


With EmailItem3

.To = ""

.Subject = "Feedback"

.HTMLBody = .HTMLBody & xStrBody


.Display

End With
Set EmailItem3 = Nothing
Set EmailApp = Nothing


End Sub
 
Upvote 0
Replace
& "Do You want to receive a free month for your subscription? Fill out our survey by clicking "<a href=" & "https://4screens.net/e/62b1566495602c01000005c6" & ">Here</a> "

with
& "Do You want to receive a free month for your subscription? Fill out our survey by clicking " & "<a href=" & "https://4screens.net/e/62b1566495602c01000005c6" & ">Here</a> "
Hi Mposwal,

Thankyou, that makes sense and worked like a treat!

Btw, do you know of any way to make this Macro work when Outlook is not opened? As the Macro only works when I have outlook open?

Or even better, do you know how to set this Macro up so that it opens up default mail application (i.e windows mail) so it is not exclusive to outlook?

Thankyou so much for all your assistance!

Kind regards,
 
Upvote 0
Hi Stewart, sorry for late rely. Your code is already working fine whether or not outlook is open. As far as windows mail concerns, I cant say much about that as I have not tried that from my end. Maybe you can check by change default mail app to Windows Mail.
 
Upvote 0
Hi Stewart, sorry for late rely. Your code is already working fine whether or not outlook is open. As far as windows mail concerns, I cant say much about that as I have not tried that from my end. Maybe you can check by change default mail app to Windows Mail.
Hi Mposwal,

No problem, for me it wasn't opening my outlook and actually bugging my outlook so I couldn't start it, but I found this simple Macro that just opened Outlook before creating the draft email.
VBA Code:
Shell ("OUTLOOK")

I've just put a note to users that they must have outlook downloaded and installed, and I'll see how that goes for now.

Thanks for all your help and suggestions, much appreciated.

Kind regards,
 
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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