Solved

Adding a Hyperlink in Outlook Message box via Excel Macro?

Posted on 2011-02-23
8
936 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook Free & Paid Tools
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

697 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