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
 
Well you could use something like this.
Code:
Sub TextToB1()
Dim FF
Dim L As String

    FF = FreeFile()

    Open "C:\test.txt" For Input As #FF
        While Not EOF(FF)
            Line Input #FF, L
            Range("B1").Value = Range("B1").Value & L
        Wend
    Close #FF
End Sub
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Ok I've tried that and all that gets entered into cell b1 is

1.26956007423338E+162651

where the text doc looks like this
1
2
3
4
5

so i want cell b1 to = 1, b2 = 2 , ect.

Thanks
Jason
 
Upvote 0
Jason

Format the cell as Text before you run the code, Excel is interpreting the concatenated string as a number.

To do the format in code use this.
Code:
Range("B1").NumberFormat = "@"
 
Upvote 0
ok so this is what I have

Sub TextToB1()
Dim FF
Dim L As String

FF = FreeFile()
Range("B1").NumberFormat = "@"
Open "C:\buildbat\devtrack_output.txt" For Input As #FF
While Not EOF(FF)
Line Input #FF, L
Range("B1").Value = Range("B1").Value & L
Wend
Close #FF
End Sub

now i get the same numbers with out the +
 
Upvote 0
Jason

Couldn't you just import the text file using Data>Get External Data...Import Text File...?

If you need code then record a macro when you do it manually.
Code:
Sub TextToB()
Dim FF
Dim L As String
Dim I As Long

    FF = FreeFile()
    Open "C:\buildbat\devtrack_output.txt" For Input As #FF
        While Not EOF(FF)
            Line Input #FF, L
            Range("B1").Offset(I).Value = L
            I = I + 1
        Wend
    Close #FF
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,421
Messages
6,119,392
Members
448,891
Latest member
tpierce

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