Select a list of hyperlinks

Joe9238

Board Regular
Joined
Jul 14, 2017
Messages
67
Hi, I have a code that lists some hyperlinks in column O to other xls documents with data that I need to pull. The data is found on a page called 'Quote' in cells B7, B8, B11 and B13. I need these cells copied and pasted into rows from A2 to D2 and following down for each hyperlink.

What I'm looking for may be along the same lines as this code but just filling in the gaps as seen. I can't really individually select the links as it is a very very long list
Code:
Sub GatherData()

    Dim wbTarget As Workbook
    Dim ary(4) As Variant
    Dim lRow As Long


Dim CodeNames As Variant, i As Long
CodeNames = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)


'For Each hyperlink in the list


For i = 1 To UBound(CodeNames, 1)


        If InStr(1, cel.Value, ".xls") > 0 Then
            Set wbTarget = Workbooks.Open(The hyperlinked workbook)   
            With wbTarget.Worksheets("Quote")
                ary(0) = .Range("B7")
                ary(1) = .Range("B8")
                ary(2) = .Range("B11")
                ary(3) = .Range("B13")
            End With
            
            With wbMaster.Worksheets(1)
                lRow = .Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).Row
                .Range("A" & lRow & ":D" & lRow) = ary
            End With
            
            wbTarget.Close SaveChanges:=False
        End If
        
'close the opened link
'Next link


End Sub

Thanks in advance :)
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
A few questions:
1. Do the hyperlinks start in O2?
2. Does each hyperlink include the full path to the workbook and the file name with extension as the text displayed?
3. Is wbMaster the workbook the code will be in?
 
Upvote 0
A few questions:
1. Do the hyperlinks start in O2?
2. Does each hyperlink include the full path to the workbook and the file name with extension as the text displayed?
3. Is wbMaster the workbook the code will be in?

Yes, the hyperlink is ‘whatever.xlswhatever’ that is highlighted and yes. Thanks for the repsonse.
 
Upvote 0
Your answer(s) are somewhat vague so you leave me guessing. Here's some code you can try under the following assumptions.
1. The sheet that contains the hyperlinks in col O must be the active sheet when you run the code.
2. The hyperlinks include the file paths and file names with file extensions.
3. You want the output to go in the worksheet with index number 1 (left-most tab) in the workbook the code is run from.
Code:
Sub GatherData()
    Dim wbTarget As Workbook
    Dim ary(3) As Variant
    Dim lRow As Long
    Dim CodeNames As Variant, i As Long

CodeNames = Range("O2:O" & Cells(Rows.Count, "O").End(xlUp).Row)
Application.ScreenUpdating = False
For i = 1 To UBound(CodeNames, 1)
    If InStr(1, CodeNames(i, 1), ".xls") > 0 Then
        If Not WorkbookOpen(CStr(Split(CodeNames(i, 1), "\")(UBound(Split(CodeNames(i, 1), "\"))))) Then
            Set wbTarget = Workbooks.Open(CodeNames(i, 1))
            With wbTarget.Worksheets("Quote")
                ary(0) = .Range("B7")
                ary(1) = .Range("B8")
                ary(2) = .Range("B11")
                ary(3) = .Range("B13")
            End With
        Else
            Set wbTarget = Workbooks(CStr(Split(CodeNames(i, 1), "\")(UBound(Split(CodeNames(i, 1), "\")))))
            With wbTarget.Worksheets("Quote")
                ary(0) = .Range("B7")
                ary(1) = .Range("B8")
                ary(2) = .Range("B11")
                ary(3) = .Range("B13")
            End With
        End If
        With ThisWorkbook.Worksheets(1)
            lRow = .Range("A" & .Rows.Count).End(xlUp).Offset(1, 0).Row
            .Range("A" & lRow & ":D" & lRow) = ary
        End With
        wbTarget.Close SaveChanges:=False
    End If
Next i
Application.ScreenUpdating = True
End Sub
Function WorkbookOpen(WorkBookName As String) As Boolean
    WorkbookOpen = False
    On Error GoTo WorkBookNotOpen
    If Len(Application.Workbooks(WorkBookName).Name) > 0 Then
        WorkbookOpen = True
        Exit Function
    End If
WorkBookNotOpen:
End Function
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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