Save XML Page using WebBrowser Document Object

BenWeber

Registered User.
Local time
Today, 00:42
Joined
Apr 27, 2006
Messages
10
I have an access program that needs to download and load XML data from a site. The code i'm using is below. It is having two problems (and i've tryed a few other syntaxes to save the file...)

1) The Save File dialog box is opening up, even tho i do pass in a path (and i've tried with both one \ and with \) and use FALSE for the second argument...

2) Even when i type the filename manually in the dialog box, it only gives options to save as HTML, not as XML. The file is only understood if it is XML. Note that if i manually use file-save as in the IE window that access has opened in the code above and then save it as xml, the saved file is fine and can be loaded...

Any thoughts on how i can save the correctly opened file as XML successfully?

I'm looking around and see the XML DOM stuff, and that would be able to do it i think, but I don't know how to use these functions on the document object instead of the HTML document which is automatically used for the InternetExplorer.Application Activex Control's document property...

Thanks,
-Ben


*** BEGIN CODE ***
Private Sub DownloadData_Click()
On Error GoTo Err_DownloadData_Click
Dim IE As Object
Dim URL As String
Dim FileName As String
Dim Password

Password = Me!Password
If IsNull(Password) Or Len(Password) < 1 Then
MsgBox ("Please enter the password for user " & Me!UserName)
Exit Sub
End If

Set IE = CreateObject("InternetExplorer.Application")
URL = Me!DataURL
IE.Navigate URL
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend

IE.Document.All("ilogin").Select
IE.Document.All("ilogin").Value = Me!UserName
IE.Document.All("ipassword").Select
IE.Document.All("ipassword").Value = Me!Password

SendKeys "{ENTER}"

While IE.busy
DoEvents 'wait until IE is done loading page.
Wend

'EVERYTHING WORKS FINE ABOVE

'Save the XML
FileName = Me!DataPath & "\temp.html"
IE.Document.ExecCommand "SaveAs", False, FileName
' THE ABOVE COMMAND OPENS UP THE SAVEAS DIALOG, DOENS"T SAVE AUTOMATICALLY, AND THEN EVEN IF YOU USE THAT IT"S SAVED AS HTML NOT XML.

'SendKeys "{ENTER}"
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend


Exit_DownloadData_Click:
Exit Sub

Err_DownloadData_Click:
MsgBox err.Description
Resume Exit_DownloadData_Click

End Sub​
 
Help

Does anyone have any thoughts at all on this?

Is there an SDK way of doing this with the generic saveas window? Should i try to get a window handle and call some SDK function?
 
Right, that's what i was suggesting i use the XML Dom for...

My question then is how do i load it from a URL when i'm going to only get to that URL if i've already entered the username and password like I did in the code snippet above...

Also, notice plz that the page itself didn't have a password and user name in authentication in it. I had to enter those fields in text boxes and then click the button on the screen (or do ENTER). Therefore I haven't been able to get the Open method to work with username and password supplied. (It may work, i just haven't been able to figure it out... Is there a way to enter information in fields like was done in the code snippet?

Thanks!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom