retrieve data with password

Gregfox

Board Regular
Joined
Apr 12, 2011
Messages
120
:confused:Hello,
I would like to use VBA code to get data from a web site. I know how to do this, but the site has a password in order to see the data. Does anyone have code to enter passwords, and then retrieve data?
Thank you.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try recording a Macro to use a Webquery and go to the site and enter your information to retrieve data, that will give you the VBA code and then in the code you would need to add the password details.
 
Upvote 0
Thank you, but I've tried that, it's the password detail I need. In the macro, I go to the site, enter username and password, import the data, and all is well, until I log out and try it again, I get an hour glass, than nothing appears in the sheet.:confused:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
What code did you end up with?

Here is a sample that should work

Code:
[FONT=Calibri]Sub Login_WebQuery()
Dim MyPost As String
Const MyUrl As String = [COLOR=green]http://www.enteryourwebsiteaddresshere
[/COLOR]Const PostUser As String = "login=User Name" [COLOR=green]'Change user name here
[/COLOR]Const PostPassword As String = "&pass=password" [COLOR=green]'Change password here
[/COLOR]    
MyPost = PostUser & PostPassword
    
With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;" & MyUrl, Destination:=Cells(1, 1))
    .PostText = MyPost
    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With
    
End Sub[/FONT]<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
Sub Login_WebQuery()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Dim MyPost As String<o:p></o:p>
Const MyUrl As String = http://www.ibm.com <Syntax error<o:p></o:p>
Const PostUser As String = "login=User Name" 'Change user name here<o:p></o:p>
Const PostPassword As String = "&pass=password" 'Change password here<o:p></o:p>
<o:p></o:p>
MyPost = PostUser & PostPassword<o:p></o:p>
<o:p></o:p>
With ActiveSheet.QueryTables.Add(Connection:= _<o:p></o:p>
"URL;" & MyUrl, Destination:=Cells(1, 1))<o:p></o:p>
.PostText = MyPost<o:p></o:p>
.BackgroundQuery = True<o:p></o:p>
.TablesOnlyFromHTML = True<o:p></o:p>
.Refresh BackgroundQuery:=False<o:p></o:p>
.SaveData = True<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>

End Sub
Thanks Trevor, but as noter above SYNTAX error on line 3
 
Upvote 0
There must be another page or url line, as when I clicked the link it took me to http://www.ibm.com/us/en/sandbox/ver2/

Even when you type in the ibm web address it still shows the above in the URL line.

Could you use your web engine to give you the exact URL line..;)
 
Upvote 0
I put the error line in "s and it lost the syntax error, but still didn't log in.
I got
User ID
Password
Case Sensitive

CODE FOLLOWS....
Sub Login_WebQuery()
Dim MyPost As String
Const MyUrl As String = "https://onlineservices.wachovia.com...gin&url=/myAccounts.aspx?referrer=authService"
Const PostUser As String = "User ID=PLACEIDHERE" 'Change user name here
Const PostPassword As String = "&Password=PLACEPASSWORDHERE" 'Change password here

MyPost = PostUser & PostPassword

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & MyUrl, Destination:=Cells(1, 1))
.PostText = MyPost
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

End Sub
 
Upvote 0
Do you have to add a line for selecting your service selection from the drop down? So you might need that and state what the service you are wanting to use.
 
Upvote 0
No, no drop down. Just the normal User ID and Password. I tried several other things , but still get User ID
Password
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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