VBA email code for outlook / referencing a hyperlink

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
893
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have this code in Excel that creates an e-mail in outlook based on cell references. One of the cell references (A8 on Sheet: Lists) is a link.
To be more precise it is the text of a hyperlink using the formula: GetURL.

Either way it is the correct address in cell A8, for example: C:\users\your name\downloads

Now when the macro creates the e-mail and references A8 the text is put in the e-mail but it does not recognize it as a link. Only part of the address has the hyperlink (C:\users\your ) and when you click on it of course it tells you that it cannot be found because it is stopping at the space between "your" and "name"..

Is there a way to fix this? Here is the code and picture of an example spreadsheet and e-mail result:

VBA Code:
Sub Owner()
'
' Owner Macro
'
       Msg = "An e-mail will be generated and sent to the owner selected." & vbCrLf & "" & vbCrLf & "Do you wish to proceed?"

    Ans = MsgBox(Msg, vbYesNo)

    Select Case Ans

        Case vbYes

    ActiveCell.Select
Range(Cells(Selection.Row, 10), Cells(Selection.Row, 10)).Select
Selection.Copy
    Sheets("Lists").Select
    Range("B5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Sheets("Database").Select
Range(Cells(Selection.Row, 1), Cells(Selection.Row, 1)).Select
Selection.Copy
    Sheets("Lists").Select
    Range("A6").Select
    ActiveSheet.Paste
  Dim OutlookApp As Object, MItem As Object
  Set OutlookApp = CreateObject("Outlook.Application")
  Set MItem = OutlookApp.CreateItem(0)
  With MItem
    .to = Sheets("Lists").Range("A5")
    .Subject = Sheets("Lists").Range("A6")
    .Body = Sheets("Lists").Range("A7") & vbCrLf & vbCrLf & Sheets("Lists").Range("A8") & vbCrLf & vbCrLf & vbCrLf & "[This is an Automated Message - Do not reply]" & vbCrLf & "Continuous Improvement Database"
    .Display
    .Send
  End With
  Sheets("Database").Select
  Case vbNo
        GoTo Quit:
    End Select

Quit:

End Sub

1575664167544.png


Thank you!

Carla
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I've often seen %20 in URLs instead of spaces. So try amending the line that sets the email body to replace spaces with %20:
Code:
    .Body = Sheets("Lists").Range("A7") & vbCrLf & vbCrLf & Replace(Sheets("Lists").Range("A8"), " ", "%20") & vbCrLf & vbCrLf & vbCrLf & "[This is an Automated Message - Do not reply]" & vbCrLf & "Continuous Improvement Database"
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,697
Members
449,331
Latest member
smckenzie2016

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