vba to navigate a webpage mentioned in worksheet cell.

NonStopLeo

New Member
Joined
Mar 25, 2010
Messages
38
Hi Friends
I have created a macro. If I run this macro I visit a URL which is mentioned in my vba code.
I want to change this url every time. so is there a way that I enter the URL in excel cell A2 (Sheet1) and vba pick the url from this cell instead of mentioning the url in vba.

Please help me change the code, currently I have below code.

<code><code>
Source = Web.Page(Web.Contents(""https://www.google.com""))
</code></code>

Thanks a lot for your usual help.
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can try this:

Just enter google into Range("A2")
Or enter CNN or People or MrExcel

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  12/2/2018  5:54:33 PM  EST
If Not Intersect(Target, Range("A2")) Is Nothing Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim ans As String
ans = Target.Value
Link = "http://www." & ans & ".com//"
    On Error GoTo NoCanDo
   ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
 
    Exit Sub
NoCanDo:
 MsgBox "Cannot open " & Link
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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