[AccessD] Automating - IE6 - File Save As

MartyConnelly martyconnelly at shaw.ca
Fri Jun 10 17:39:37 CDT 2005


You maynot be able to do this for security reasons on second method.
Ran this okay from WinXP SP2, Access97, IE6.0.2900  xpsp2 patches

Here are two ways.

'This gets around security limitations
'will only save between <body> </body> tags
CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\temp\myurlsaved.htm", 
2, True).Write _
   objExplorer.Document.Body.innerHTML

'or alternate method that security may clobber, saves everthing with 
fileopen box used
With objExplorer.Document
  If .queryCommandEnabled("saveAs") Then .execCommand "saveAs", False, 
"C:\temp\myurl.htm"
 End With

Anywho here is some rough test code, that works both ways.
You can throw out all the commented objdocument code at bottom.


Sub testIESave(strpassHTML As String)
'------------------
'testIESave "http://www.Viescas.com/"
Dim objExplorer As Object
Dim objDocument As Object
Dim strComputer As String

Dim strReturn As String

Set objExplorer = CreateObject("InternetExplorer.Application")

'objExplorer.navigate "about:blank"
objExplorer.navigate strpassHTML
objExplorer.Toolbar = 1 'or 0 to turnoff toolbar turned off maynot save 
all html source
objExplorer.StatusBar = 0
objExplorer.Width = 800
objExplorer.Height = 570
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
'dont't need to navigate to file or http site
'just drop html string in document object
'objExplorer.Navigate "file://c:\temp\test.html"
'objExplorer.Navigate "http://www.Viescas.com/"
'objExplorer.Navigate "http://checkip.dyndns.org/"

Do While (objExplorer.Busy)
Loop
Dim webtx As String
Dim strHTML As String
'will only save between <body> </body> tags
CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\temp\myurlsmall.htm", 
2, True).Write _
   objExplorer.Document.Body.innerHTML
'alternate method security may clobber saves everything
With objExplorer.Document
  If .queryCommandEnabled("saveAs") Then .execCommand "saveAs", False, 
"C:\temp\myurl.htm"
 End With
 
'Set objDocument = objExplorer.Document
'objDocument.Open
'objDocument.writeln "<html><head><title>My Continuous 
Pictures</title></head>"
'you probably don't need all this but you could throw in some css
'objDocument.writeln "<body bgcolor='red';" & _
'    " {   background-attachment: fixed; background-position: 97% 
bottom; " & _
'      "  background-image= 'url(logoBackGround.gif)';background-repeat: 
no-repeat;" & _
'       " padding: 5px;font-family='Georgia';font-size: 80%;} >"
   
'objDocument.writeln "<table width='100%'>"
'objDocument.writeln "<tr>"
'objDocument.writeln "<td width='20%'><b>Pictures</b></td>"
'objDocument.writeln "</tr>"
'objDocument.writeln "</table>"

'objDocument.writeln "<h3>Method #2:</h3><img src = ""C:\Access 
files\CandaceTripp\picture\shakes.bmp"" Width = ""150"" Height = ""75"" 
alt = ""Random Image #4"" />"

'objDocument.writeln strpassHTML
'objDocument.writeln "</body></html>"
'objDocument.Write()
'objDocument.Close
'MsgBox "finished"
Set objExplorer = Nothing
Set objDocument = Nothing

End Sub


Drawbridge, Jack: #CIO - BPI wrote:

>Have had no responses with original post. I believe it is a question of automating IE, and how to get to CommonDialog in order to do the File Save As.
>
>IE does a fantastic job of removing relative links and downloading a clean set of files when using the File Save As webpage complete option. I do not want to do the File saves manually. There must be a means to automate this in VBA???
>
>Any advice/help on this would be greatly appreciated.
>
>Thanks,
>
>jack
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Drawbridge,
>Jack: #CIO - BPI
>Sent: Thursday, June 2, 2005 3:01 PM
>To: Access Developers discussion and problem solving
>Subject: [AccessD] A2K talking to IE6 - File Save As
>
>
>Looking for help/advice or sample code to open IE6 from code in A2K. Am interested in how to do a File| Save As Webpage, Complete.
>We have a database of 60000 companies and want to put extracts of selected 100-500 companies (html and graphics etc) onto a CD for use with Offline Browser.
>
>Can not figure out how to get to IE6 File | Save As.
>
>I have some code to open a page with IE browser and save all the links on the page.
>
>Any help would be appreciated.
>
>TIA 
>
>jack
>
>'---- CODE to GET the Links from a given page ----
>'---------------------------------------------------------------------------------------
>' Procedure : GetLinks
>' DateTime  : 2005-06-02 14:19
>' Author    :
>' Purpose   : get all links from a named webpage URL
>'---------------------------------------------------------------------------------------
>'
>Sub GetLinks()
>
>' ** need to set a reference to
>' ** Microsoft Internet Controls
>
>    Dim IeApp As InternetExplorer
>    Dim sURL As String
>    Dim IeDoc As Object
>    Dim i As Long
>    
>   'Create new instance of IE
>    Set IeApp = New InternetExplorer
>    
>    'May wish to make IeApp visible
>    'apparently some things don't work
>    'unless it's visible
>    IeApp.Visible = False
>    
>    'define the page to open
>    sURL = "www.diligens.com"
>    
>    'navigate to the page based on URL
>    IeApp.Navigate sURL
>   
>    'Pause until the webpage is completely loaded
>    Do
>    Loop Until IeApp.ReadyState = READYSTATE_COMPLETE
>    
>    'Create instance of Document object
>    Set IeDoc = IeApp.Document
>  
>    'Loop through the document's links collection.
>    For i = 0 To IeDoc.links.Length - 1
>        Debug.Print IeDoc.links(i).href
>    Next i
>    
>    'Clean up
>    Set IeApp = Nothing
>    Set IeDoc = Nothing
>End Sub
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list