VBA Help: Retaining Hyperlinks

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
246
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am using Ron de Bruin's script (modified version) to filter and email a list using Outlook. The files are sent as xlsx extensions in the email.
The original excel sheet contains URL hyperlinks. However, when it is filtered and copied to a new workbook to attach, those hyperlinks are not retained.
But when I copy and paste the column of URLS to the email attachment, the hyperlinks work. So this is the section where it is not working.
I even added a
VBA Code:
Dim Hlink As Hyperlink

VBA Code:
Set My_Range = Worksheets("Sheet1").Range("$a$4:$M20")  '(How Do I change M20 to &lastrow that works?)
My_Range.Parent.Select


NewTab ("sheet2")
Worksheets("sheet2").Cells.ClearContents

My_Range.Copy Destination:=Worksheets("sheet2").Range("$A$4:M20")
   
     For Each Hlink In My_Range.Hyperlinks
     
         Worksheets("sheet2").Hyperlinks.Add Anchor:=Hlink.Range, Address:=Hlink.Address, TextToDisplay:=Hlink.TextToDisplay
     
     Next Hlink
Sheets("sheet2").Select
Sheets("sheet2").Move

    With Selection.Font
        .Name = "Calibri"
        .Size = 7.5
    End With
tempFilename = TempFilePath & File & ".xlsx"

ActiveWorkbook.SaveAs FileName:=tempFilename, _
        FileFormat:=xlOpenXMLWorkbook
Workbooks(File & ".xlsx").Close
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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