Open a webpage using vba code

CrunchMasterMatt

Board Regular
Joined
Jul 20, 2012
Messages
123
Hi All, I'm trying to open a web address via VBA macro and also have a cells value copied into the clipboard memory, so once the user gets to the webpage, then can paste the data in the clipboard into a box in the webpage.

for example, say I want to open weather.gov and have in memory "92624" as a zipcode, how do I do this?

Thank You!!!!

PS Ive created a hyperlink and can open the webpage using it, but that ONLY executes the hyperlink - and doesnt run any code which would otherwise allow me to copy the zipcode first, before navigating via the hyperlink.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi, thanks for helping but this isn't what I'm trying to do.

I'm trying to click a button on my worksheet and:

1) Have it run a Sub that copies a value from a cell on my worksheet;

2) Open a webpage;

(and of course have the copied value from the cell remain available for my user to paste into a box on the webpage).
 
Upvote 0
Hey Crunch. I have something that may help you. I've worked on a UserForm with a CommandButton and TextBox, that I can copy data from the TextBox and then Paste to the Web HTMLInputBox. See if this works for you. Here's an example of what I'm using right now. Now this will copy the data but I have to paste it by using CTRL V or Right Clicking on the mouse and pasting the old fashion way. Let me know how it goes.

Private Sub CommandButton4_Click()

Dim objData As DataObject
Dim strClipBoard As String
Set objData = New DataObject
' Clears the clipboard
objData.SetText ""
objData.PutInClipboard
' Puts the text from an textBox into the clipboard
strClipBoard = Me.TextBox17.Value
objData.SetText strClipBoard
objData.PutInClipboard
' Gets the text on the clipboard into a string variable
objData.GetFromClipboard
strClipBoard = ""
strClipBoard = objData.GetText

End Sub
 
Upvote 0
Oh, in addition, I'am also using a code to send that data from a Textbox which was made for the User Name and Commandbutton for submitting the data. The only problem in which I'm trying to resolve now is not opening a new web form or doc. Instead I just want to Grab or Activate the existing web page I already have up. Take a look at this code and see if it helps as well. If you find out how to have it not open a new window, let me know sir. I would appreciate it.

Private Sub CommandButton1_Click()

Dim IE As Object
Dim Doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement

Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
IE.navigate "http://www.weather.gov/"

'Wait for initial page to load

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

Set Doc = IE.Document

'Get the only form on the page

Set LoginForm = Doc.forms(0)

Set UserNameInputBox = LoginForm.elements("inputstring")
UserNameInputBox.Value = TextBox1.Text

Set SignInButton = LoginForm.elements("btnSearch")
SignInButton.Click

'Wait for the new page to load

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

'Get the HTML document of the new page

Set Doc = IE.Document

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,666
Members
448,977
Latest member
moonlight6

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