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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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.
 

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491
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
 

residnt

Board Regular
Joined
Nov 19, 2002
Messages
168
Awesome thanks,

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

I've tried this

SendKeys """, True

Thanks
Jason
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

residnt

Board Regular
Joined
Nov 19, 2002
Messages
168
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

residnt

Board Regular
Joined
Nov 19, 2002
Messages
168
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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?
 

residnt

Board Regular
Joined
Nov 19, 2002
Messages
168
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
 

Forum statistics

Threads
1,136,592
Messages
5,676,690
Members
419,644
Latest member
KeelsM

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
Top