PC Review


Reply
Thread Tools Rate Thread

Change Save Dir in IE (VBA)

 
 
Dave N
Guest
Posts: n/a
 
      7th May 2008
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
 
Reply With Quote
 
 
 
 
T Lavedas
Guest
Posts: n/a
 
      7th May 2008
On May 7, 12:22 pm, Dave N <Da...@discussions.microsoft.com> wrote:
> 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/
 
Reply With Quote
 
Dave N
Guest
Posts: n/a
 
      8th May 2008
Thanks for your help with this Tom,
My application runs in Excel and I am using the Internet Explorer object
model (references the WebBroser Control - ShDocVw.dll). What I really need to
know is is there a way of changing the default Save As directory through this
or any other way while using VBA? You mentioned changing the registry using
WScript.Shell object - can this be done in VBA?
Regrards
Dave

"T Lavedas" wrote:

> On May 7, 12:22 pm, Dave N <Da...@discussions.microsoft.com> wrote:
> > 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/
>

 
Reply With Quote
 
T Lavedas
Guest
Posts: n/a
 
      8th May 2008
On May 8, 3:45 am, Dave N <Da...@discussions.microsoft.com> wrote:
> Thanks for your help with this Tom,
> My application runs in Excel and I am using the Internet Explorer object
> model (references the WebBroser Control - ShDocVw.dll). What I really need to
> know is is there a way of changing the default Save As directory through this
> or any other way while using VBA? You mentioned changing the registry using
> WScript.Shell object - can this be done in VBA?
> Regrards
> Dave
>
> "T Lavedas" wrote:
> > On May 7, 12:22 pm, Dave N <Da...@discussions.microsoft.com> wrote:
> > > 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/


Yes, the Wscript.Shell class can be used, either the way I showed you
(late bound)...

sub setSaveAsDir(sStartin)
Const sKey = "HKCU\Software\Microsoft\Internet Explorer\Main\Save
Directory"
with createobject("wscript.shell")
.RegWrite sKey, sStartin, "REG_SZ"
end with
end sub

Or the wshom.ocx control library (Windows Script Host Object Model)
can be added to the available objects list (Object browser/
References). Then early binding can be used ...

Sub setSaveAs(sStartin)
Dim oWSH As New WshShell
Const sKey = "HKCU\Software\Microsoft\Internet Explorer\Main\Save
Directory"
oWSH.RegWrite sKey, sStartin, "REG_SZ"
End Sub

Just call the routine with the appropriate pathspec from the code that
activates the SaveAs or initializes the IE class, whichever is
appropriate.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      9th May 2008
Is the CSV file linked from a URL on a page, or the result of a form
submission ?

If a link (or form submission using GET) then you could probably download it
directly using xmlHttp.

Tim


"Dave N" <(E-Mail Removed)> wrote in message
news:A3338DA5-BD10-4E63-B5B1-(E-Mail Removed)...
> Thanks for your help with this Tom,
> My application runs in Excel and I am using the Internet Explorer object
> model (references the WebBroser Control - ShDocVw.dll). What I really need
> to
> know is is there a way of changing the default Save As directory through
> this
> or any other way while using VBA? You mentioned changing the registry
> using
> WScript.Shell object - can this be done in VBA?
> Regrards
> Dave
>
> "T Lavedas" wrote:
>
>> On May 7, 12:22 pm, Dave N <Da...@discussions.microsoft.com> wrote:
>> > 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

>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I change the default save folder when I select File-Save? jrparish Microsoft Outlook Discussion 1 13th Nov 2009 06:36 PM
Change Outlook item programmatically - "Do you want to save change Snixtor Microsoft Outlook Discussion 6 17th Dec 2008 12:30 AM
HELP! - FP won't save pictures, can't change folder/action of save =?Utf-8?B?TmF0ZSBL?= Microsoft Frontpage 4 29th Jan 2006 11:40 PM
olMailItem.Save doesn't save change to subject OL2003 Tony Gravagno Microsoft Outlook VBA Programming 3 16th May 2005 01:19 PM
Why system asks me to save change even after I call save method(VB.NET) =?Utf-8?B?c3RlZWxsb2Nr?= Microsoft Excel Programming 2 27th Apr 2004 04:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 AM.