Hi,
I need some help with automating Internet Explorer using VBA. I have an
application to runs a report on our Internet based system and which can be
downloaded as a csv file. In order to save this file into the correct
location I need to change the directory that intintially pops up in the 'Save
As' dialog box. This defaults to the last location used. Can anyone please
suggest a way of doing this? For example, in Excel I would use the ChDir
statement, is there a similare statement for IE?
Any help would be much appreciated!
Dave
Are you actually programming in an HTML document? I ask, because it
really makes a difference what is available to you. If so, client
side scripting, which uses VBScript, not VBA, has many security
restrictions placed on it. For example, there is a "Save Directory"
entry in the registry that controls where the SaveAs dialog opens in
IE. To alter this, the normally unsafe for scripting WScript.Shell
object can read/write this registry item. However, IE will restrict
access to this object to varying degrees, depending on the security
level set. In the Medium setting, a request to permit execution of
ActiveX controls is displayed each time the page is loaded. In High,
the page just fails to load with an error. You do not want to set it
lower. The source can be flagged as trusted, but all of this requires
user intervention.
An example of HTML code that will do this is (changing the location to
the root of C
...
<html>
<script language=vbs>
sKey = "HKCU\Software\Microsoft\Internet Explorer\Main\Save Directory"
with createobject("wscript.shell")
.RegWrite sKey, "C:\", "REG_SZ"
end with
</script>
<body>
TESTING
</body>
However, if similar code were run from a script that were controlling
IE via it's InternetExplorer.Application ActiveX interface, these
restrictions would not be in force. The Windows Scripting Host (WSH)
is one such way to gain access in this way, another is via one of the
Office application VBA implementations.
If this isn't enough information, I guess it would help to know more
exactly where your application runs to be able to provide more advice.
HTH,
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/