Import data and Attach Hyperlink

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - I'm currently running code that opens workbook2 copies data and then closes workbook2. Is there a way to insert a hyperlink for workbook2 into column "B" of the row the data is being pasted? Here's the code I'm using to import.

Code:
Dim ws1 As WorksheetSet ws1 = Sheet1


sPath = "\\Server\Folder1\" & ws1.Range("A5")


If SetFilePath(sPath) = 0 Then
    MsgBox "Error in setting the path - " & sPath
Else
    sFile = Application.GetOpenFilename("Excel,*.xls;*.xlsx")
End If


If sFile <> False Then
    Set WB = Workbooks.Open(sFile)
Else
    MsgBox "No File Selected"
        Exit Sub
End If


Set ws2 = WB.Sheets("Data")
Set CsNm = WB.Sheets("Data").Range("A1")


Set found = ws1.Range("B:B").Find(what:=CsNm, LookIn:=xlValues, lookat:=xlWhole)
If found Is Nothing Then
    fRow = InputBox("Name match not found - Enter Row")
    Else
    fRow = found.Row
End If




With ws2


    .Range("J8").Copy
    ws1.Range("C" & fRow).PasteSpecial xlPasteValues


    .Range("J9").Copy
    ws1.Range("D" & fRow).PasteSpecial xlPasteValues


    .Range("J3").Copy
    ws1.Range("E" & fRow).PasteSpecial xlPasteValues


End With


WB.Close False
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I added this code right before WB.Close False and it works perfectly.

Code:
ws1.Hyperlinks.Add Anchor:=ws1.Range("B" & fRow), Address:=sFile
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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