ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Login to intranet and download excel file using vba (https://www.excelbanter.com/excel-programming/453610-login-intranet-download-excel-file-using-vba.html)

[email protected]

Login to intranet and download excel file using vba
 
Hi,

I have company wiki which contains some attachment in it. So first I need to login to the wiki and then download the excel file.

I have tried this:

Dim strValue As String
Dim myValue As Variant
Dim myHTMLElement As IHTMLElement
Dim myHTMLElement1 As IHTMLElement
strValue = "http://...wiki/"

On Error GoTo err_clear

myBrowser.Visible = True
myBrowser.navigate strValue


Do
DoEvents
Loop Until myBrowser.readyState = READYSTATE_COMPLETE


Set HTMLDoc = myBrowser.document
' Load all the details to the login page
HTMLDoc.all.Item("os_username").Value = "username"
myValue = InputBox("Password for your account:")
If myValue = "" Then Application.Quit
HTMLDoc.all.Item("os_password").Value = myValue

'Finds the login button and proceeds the click event
For Each myHTMLElement In HTMLDoc.getElementsByTagName("input")
If myHTMLElement.ID = "loginButton" Then
myHTMLElement.Click
Do While myBrowser.Busy: DoEvents: Loop
Do Until myBrowser.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Workbooks.Open ("http://...wiki/download/List.xls")
Exit For
End If
Next


err_clear:
If Err < 0 Then
MsgBox Err.Description
Err.Clear
Exit Sub
End If


When I run the above code it just copies the login page my excel sheet.

Could anyone suggest me what should be done?

Thanks

GS[_6_]

Login to intranet and download excel file using vba
 
Google is your friend...

Check out using *URLDownloadToFile*

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

[email protected]

Login to intranet and download excel file using vba
 
Thanks for your suggestion.

I tried "URLDownloadToFile", but it doesn't give me the desired result. It downloads the login page and stores it to the sheet.

Is there any other way ?

If I use *myHTMLElement.Click* instead of *Workbook.Open* then I get the download popup window from Internet explorer and clicking on save gives me the list I need but I need code to to all the work.

Any help would be great.

GS[_6_]

Login to intranet and download excel file using vba
 
Thanks for your suggestion.

I tried "URLDownloadToFile", but it doesn't give me the desired result. It
downloads the login page and stores it to the sheet.


If your file is stored on the web then that file should be downloaded to the
folder you specify, after which you can open it in Excel...

Sub UrlDownload()
' Downloads a specified file from a specified URL folder,
' to a folder of a specified path.
' **This is IE dependant and writes to the IE cache!
Const sSrc$ = "UrlDownload"

Dim sSrcFile$, sTgtFile$, n&

'Download the file
sSrcFile = "http://...wiki/download/List.xls"
sTgtFile = ThisWorkbook.Path & "\List.xls"
On Error Resume Next
n = URLDownloadToFile(0, sSrcFile, sTgtFile, 1, 0)

'Open the file
Workbooks.Open sTgtFile
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


All times are GMT +1. The time now is 03:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com