Solved

Adding a Hyperlink in Outlook Message box via Excel Macro?

Posted on 2011-02-23
8
931 Views
Last Modified: 2012-08-13
Hi Guys, I currently have an Excel Macro that opens Excel tabs into Outlook and sends them as an attachment. I would like the reciever of this e-mail to see a Hyperlink in the the e-mail body.  . How to I add this into the below VB code so it does it automatically?

Sub Mail_Sheets_Array()
'Working in 2000-2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim sh As Worksheet
    Dim TheActiveWindow As Window
    Dim TempWindow As Window

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    'Copy the sheets to a new workbook
    'We add a temporary Window to avoid the Copy problem
    'if there is a List or Table in one of the sheets and
    'if the sheets are grouped
    With Sourcewb
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("FIEQ Dailies", "SCRIPS JAN 11", "F&R Counterparty", "F&R Write Offs", "CHEAP DIV RIGHTS JAN 11", "Structured- UKSCR")).Copy
    End With

    'Close temporary Window
    TempWindow.Close

    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xls": FileFormatNum = -4143
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xls": FileFormatNum = -4143
                    Else
                        FileExtStr = ".xls": FileFormatNum = -4143
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = -4143
                Case Else: FileExtStr = ".xls": FileFormatNum = -4143
                End Select
            End If
        End If
    End With
 Sheets("FIEQ Dailies").Activate
   
    Columns("W:AB").Select
    Selection.Delete Shift:=xlToLeft
'    Columns("X:X").Select
'    Selection.Delete Shift:=xlToLeft
   '    Change all cells in the worksheets to values if you want
        For Each sh In Destwb.Worksheets
            sh.Select
            With sh.UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select

    End With
           Application.CutCopyMode = False
            Destwb.Worksheets(1).Select
    Next sh


    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "" & Sourcewb.Name & " " _
                 '& Format(Now, "dd-mmm-yy h-mm-ss")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .To = "cscanlan@mfglobal.com;dbruyns@mfglobal.com;sbruce2@mfglobal.com;vfoster@mfglobal.com;shawksworth@mfglobal.com;nheale@mfglobal.com; anussbaum@mfglobal.com; mturner@mfglobal.com; swagstaff@mfglobal.com; chenstock@mfglobal.com; adwilliams@mfglobal.com; mwhitehead@mfglobal.com; obottomley@mfglobal.com"
                 
            .CC = ""
            .BCC = ""
            .Subject = "FIEQ Dailies - "
            .Body = "Regards Vishal"
            .Attachments.Add Destwb.FullName
            'You can add other files also like this
            '.Attachments.Add ("C:\test.txt")
          .dISPLAY
        End With
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
0
Comment
Question by:JCutcliffe
  • 4
  • 3
8 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34960750
A hyperink to what sorry?
0
 

Author Comment

by:JCutcliffe
ID: 34960824
Adding a hyperlink to an Excel Path something like "g:\FITR\File.xls" so the approver can look at the Excel file & decide if its okay.The Reciever of the e-mail will see the Hyperlink, click on it & then Aprrove or Reject via Voting Buttons.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34962040
Assuming HTML then

Application.ActiveInspector.CurrentItem.HTMLBody = "<p>Lookit this ... a Server file reference: <a href=""file:\\Server-Name\Root\Sub-Folder\filename.ext"">file link</a></p>"

of course this needs merging in with the other text.

Chris
0
 

Author Comment

by:JCutcliffe
ID: 34970474
Hi Chris,
I am using this code, but its not working. I am getting no error messages either. It just
shows up without a mail message without any hyperlink. Do i need a specail add-in? Justin
  With OutMail
            .To = "cscanlan@mfglobal.com;"
               
            .VotingOptions = "Approve;Reject"    'you can include what you want in fact

            .CC = ""
            .BCC = ""
            .Subject = "FITR Dailies - "
            .Application.ActiveInspector.CurrentItem.HTMLBody = "G:\Restricted\UKMFG-TS-AM-EUC03\TRES\FITR - P11 Feb'11\FITR Oracle Dailies Feb'11.xlsm"

                  .Display
        End With
'        On Error GoTo 0
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34971284
Modified slightly to attach to your mail item.

Chris
With OutMail
            .To = "cscanlan@mfglobal.com;"
                
            .VotingOptions = "Approve;Reject"    'you can include what you want in fact

            .CC = ""
            .BCC = ""
            .Subject = "FITR Dailies - "
            outmail.HTMLBody = "G:\Restricted\UKMFG-TS-AM-EUC03\TRES\FITR - P11 Feb'11\FITR Oracle Dailies Feb'11.xlsm"

                  .Display
        End With
'        On Error GoTo 0

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34971337
Looking again ... you didn't apply the formatting from my post so try:

Chris
With OutMail
            .To = "cscanlan@mfglobal.com;"
                
            .VotingOptions = "Approve;Reject"    'you can include what you want in fact

            .CC = ""
            .BCC = ""
            .Subject = "FITR Dailies - "
            .HTMLBody = "<p><a href=""file:G:\Restricted\UKMFG-TS-AM-EUC03\TRES\FITR - P11 Feb'11\FITR Oracle Dailies Feb'11.xlsm"">file link</a></p>"

                  .Display
        End With
'        On Error GoTo 0

Open in new window

0
 

Author Comment

by:JCutcliffe
ID: 34972195
Hi Chris,

I adapted to your code (see below) & the path appears in html in Outlook but when I press <CTRL> + Open, nothing happens. Any ideas?
 With OutMail
            .To = "cscanlan@mfglobal.com;"
               
            .VotingOptions = "Approve;Reject"                                 .Subject = "FITR Dailies - "
                      OutMail.HTMLBody = "<p><a href=>\intldn\uk-finance\Accdata\Restricted\UKMFG-TS-AM-EUC03\TRES\FITR - P11 Feb'11\FITR Oracle Dailies Feb'11.xlsm</a></p>"

                  .Display
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34972485
What is your default mail format ... HTML?

Chris
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now