Discussion Locked

Opening an HTML file in IE from VBA?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Im having problems opening this HTML file from ACCESS in code. In an if statement, i have this code:

RetVal = Shell("c:\Program Files\Internet Explorer\Iexplore.exe", 1)
AppActivate RetVal, True
SendKeys "%FO"
SendKeys filename

I know that this code wont work because im missing a SendKeys line telling the open form to press enter for example. But that is not the problem, either Explorer opens with my homepage, or Access tries to open a New DB. My SendKeys commands are being directed to the Access window instead of the IE window. If anyone has any ideas about this it would be truly appreciated. Thanks

Justin

5 replies

by steved

Your problem with SendKeys may well be a timing problem. You might try inserting a delay.

But actually SendKeys is by far the least reliable way to communicate with another program like this. If you have only one HTML file to open under program control, just include its name on the Iexplore command line, like this:

RetVal = Shell("c:\Program Files\Internet Explorer\Iexplore.exe " & filename, 1)

If you want to change HTML files under VBA program control, DDE will be a much more reliable way than SendKeys.

I hope this helps.

Steve Diamond

by bowjangles

I have tried this before, but it simply gives me the error "File not found". And i cant understand why, the file exists and it is located at filename.
filename = "c:\justin\aa2u_proj_def.htm"
And that file exists in that directory, that is why i tried using the SendKey function, but like you said it wont work unless you put a delay, which is not very reliable, i was wondering if you knew why i was getting the error "File not found". I would give you the points, but i still had a question toask you, so dont worry, these points will be yours if you can solve my small problem...Thanks.

Justin

by steved

I'm puzzled why it would tell you "file not found." I've tried the code exactly as I wrote it in my answer, and it works just fine for me. My only thought is a desperate one. Make sure that there's a space between "iexplore.exe" and your filename inthe shell command parameter. To make this clearer, I should have written it like this:

RetVal = Shell("c:\Program Files\Internet Explorer\Iexplore.exe" & " " & filename, 1)

If that's not the problem, then I have to think there's something wrong with the filename itself. Have you tried manually opening a DOS command window and typing this:

"c:\Program Files\Internet Explorer\Iexplore.exe" c:\justin\aa2u_proj_def.htm

If that works, then there's no good reason why the shell function shouldn't work.

Good luck.

Steve Diamond

This discussion is closed to new replies.