Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

'Replacing the "B8" Range from this code:

    Set IE = CreateObject("InternetExplorer.Application")
    
    Set MainPage = ThisWorkbook.Worksheets("Sheet1")
        With IE
            .Visible = True
            .Navigate MainPage.Range("B8").Hyperlinks(1).Address
            Do Until .ReadyState = 4: DoEvents: Loop
        End With

Replacing it with this code below:

Sheets("sheet1").Select
rowNum = Range("B1").Value
   Range(Cells(rowNum, 2), Cells(rowNum, 2)).Select

This code determines the cell address. I would like this code to replace the Range("B8") where I .navigate to a hyperlink.

I'm new to VBA and struggling to do this.

question from:https://stackoverflow.com/questions/66064860/how-can-i-add-these-two-vba-codes-together

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
461 views
Welcome To Ask or Share your Answers For Others

1 Answer

If I understand correctly, you want to use the selected cell as the parameter for your .navigate

The first part of code can be

Sheets("sheet1").Activate
rowNum = Range("B1").Value
' The original code creates a range that starts and ends at the same place 
' so the Range(...) i dont think is needed

Cells(rowNum, 2).Select

then the call just becomes

    With IE
        .Visible = True
        .Navigate ActiveCell.Hyperlinks(1).Address
        Do Until .ReadyState = 4: DoEvents: Loop
    End With

is that what you are looking for?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...