Sendkeys and macro shortcut key

jackms

New Member
Joined
Dec 28, 2005
Messages
21
I am a beginner Macro coder and was hoping someone can help me with this problem.

I have a macro that activates a specific Internet Explorer window (that's already open) and then uses SendKeys to type a URL in the address bar.

The problem is, i would like to assign a shortcut to the macro. But when I run the macro using the shortcut key, it's as if the Ctrl key is still pressed (so if, for example, I have SendKeys "p" - it opens up the Explorer print function, instead of just typing the letter p). If i run the macro using Tools,Macro... it works fine. Any suggestions?

This is the macro:

ssnText = Application.WorksheetFunction.Text(ActiveCell.Value, "000000000")

AppActivate Title:="yyyy"

Application.Wait Now() + TimeValue("00:00:01") ' Wait a sec (i got this from mrexcel)

SendKeys "%d" & "https://www.yyyy.com/searchssn.asp?SSN=" & ssnText & "{ENTER}"
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
jackms,
Why not just use the shell command to call explorer with the address?

Code:
Shell ("explorer ""http://www.mrexcel.com""")

HTH
Cal
 

jackms

New Member
Joined
Dec 28, 2005
Messages
21
Thanks for replying.

Shell command opens a new browser window (i also tried using FollowHyperlink event - that also opens new window). Then I can't get the page I want because I'm not logged in to the website.

That's why I need to go to the web page from an already open browser where I've already logged in.
 

jackms

New Member
Joined
Dec 28, 2005
Messages
21
After fooling around a bit more, i came up with the following solution.

I added the following line to the beginning of the macro:

VBA Code:
Application.Wait Now() + TimeValue("00:00:02")

I think this works becasue it allows time for the user to release the control key before Explorer is activated. It seems like if control key is still pressed at the time Explorer is activated, then the control key gets "stuck".

Not a perfect solution, but it works.
 
Last edited by a moderator:
Solution

Watch MrExcel Video

Forum statistics

Threads
1,118,081
Messages
5,570,088
Members
412,310
Latest member
mark884
Top