send keys error

residnt

Board Regular
Joined
Nov 19, 2002
Messages
168
Hello all,

I'm having a bit of a problem using the sendkeys command. It is adding the keystrokes into the macor and not the focused window.

Here is what I am running just for the tests.


Call Shell("cmd.exe", vbNormalFocus)
SendKeys "cd d:\~"

Thanks
residnt
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Do it in parts. Each SendKeys statement should be one keyboard stroke.

First just run the code to open. Then write down each key-stroke you used to do what you wanted. Then add the SendKeys staments to mimic your strokes, Tabs, Cursor movements, and others one after another. You have mixed steps in your sample.
 
Upvote 0
Like Joe said : do it in parts or
write a batch file with the commands you want and then execute the batch file. In this way you don't have to worry about missing key-strokes...

Code:
Sub MakeBatFile()
Filenr = FreeFile() 
Open "C:\MyBatFile.bat" For Output As #Filenr 
   Print #Filenr, "cd d:\~" 
   Print #Filenr, "dir > AllFilenames.txt"
   'etc.
   'Print #Filenr, your command here
   'Print #Filenr, your command here
Close #Filenr 
Shell "C:\MyBatFile.bat" 
End Sub
 
Upvote 0
Awesome thanks,

Now how do i sendkey this character ", everytime I try it messes things up.

I've tried this

SendKeys """, True

Thanks
Jason
 
Upvote 0
Jason

What are you actually trying to use SendKeys to do?

Using SendKeys can be flaky, perhaps you can do what you want another way.
 
Upvote 0
I'm using it to edit a test doc to remove some characters in notepad. I can get it to do all of the steps just not removing the " as the line of code doesn't work.
 
Upvote 0
Jason

Something like that could be done using Excel VBA's file input/output methods and string functions.

That would be far more reliable than using SendKeys.
 
Upvote 0
how do i do that. I'm having a problem with the outputs right now as the sendkeys are adding in extra letters

Thanks
Jason
 
Upvote 0
Jason

How it would be done really depends on exactly what you are doing?

Can you give more details, and perhaps post some sample data?
 
Upvote 0
ok so where is what I want to do

i have a text file with say 20 lines. What I want to do is take that info and copy it into say cell b1. i can do this if I open up notepad and use sendkey but is there any other way to do this without opening anything?

Thanks
Jason
 
Upvote 0

Forum statistics

Threads
1,217,317
Messages
6,135,833
Members
449,965
Latest member
Ckl43

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top