QueryTable.Connection Property

flaviu123

New Member
Joined
Aug 20, 2014
Messages
44
Hello! Does anyone know how to adjust for Connection to navigate to the address that was under the hyperlink?


Code:
Sub GetHtmlLinck()

    Dim objWeb As QueryTable
    Dim sWebTable As String
    Dim vAddr As String
    
     'You have to count down the tables on the URL listed in your query
     'This example shows how to retrieve the 2nd table from the web page.
    sWebTable = 12
     'Sets the url to run the query and the destination in the excel file
     'You can change both to suit your needs
    ThisWorkbook.Sheets("Sheet4").Activate
    vAddr = ActiveCell.Hyperlinks(1).Address
    Set objWeb = ActiveSheet.QueryTables.Add( _
    Connection:="URL;vAddr", _
    Destination:=Range("C4"))
     
    With objWeb
        
        .WebSelectionType = xlSpecifiedTables
        .WebTables = sWebTable
        .Refresh BackgroundQuery:=False
        .SaveData = True
    End With
    Set objWeb = Nothing
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Instead of this:
Code:
Set objWeb = ActiveSheet.QueryTables.Add(Connection:=[COLOR="#FF0000"]"URL;vAddr"[/COLOR], Destination:=Range("C4"))
Try this:
Code:
Set objWeb = ActiveSheet.QueryTables.Add(Connection:=[COLOR="#FF0000"]"URL;" & vAddr[/COLOR], Destination:=Range("C4"))
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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