469,649 Members | 1,234 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Write a variable to Notepad

Hi,
I am trying to write out an array of string variables to Notepad. I
can't get SendKeys to accept the string variable only literal quoted
strings.

I DO NOT want the hassle of writing to a file
I DO NOT want to write to a report
I DO NOT want to write to a form

My user requires I write this array of string variables out to Notepad,
and that I leave Notepad open. (They will be copying these strings and
pasting them into another application)

I tried three quotes and then the variable, but that didn't work

Dim strMyString As String 'Just one string I know
strMyString = "This is a string I want to output to Notepad"

'Then I opened notepad
SendKeys """ & strMyString & """ 'This doesn't work

Ahhhh.... Why is something so simple SO HARD

Any help is GREATLY appreciated
Vmusic

Mar 18 '06 #1
11 15756
Vmusic wrote:
Ahhhh.... Why is something so simple SO HARD


Because it's incredibly stupid?

Mar 18 '06 #2
This works for me:

Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub

Dr Ju Chao
Dip Ed, BSci BCom, PHD

Mar 18 '06 #3
On 17 Mar 2006 21:21:45 -0800, "Lyle Fairfield" <ly***********@aim.com> wrote:
Vmusic wrote:
Ahhhh.... Why is something so simple SO HARD


Because it's incredibly stupid?


No, some stupid things are quite easy to do as I have often discovered.

Mar 18 '06 #4
"JuChao" <jc******@hotmail.com> wrote in
news:11*********************@z34g2000cwc.googlegro ups.com:
This works for me:

Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub

Dr Ju Chao
Dip Ed, BSci BCom, PHD

Using sendkeys like in this example is incredibly dangerous.

--
Bob Quintal

PA is y I've altered my email address.
Mar 18 '06 #5
My user requires I write this array of string variables out to Notepad<<
I'm not sure what you mean by array.
Maybe this will work and you don't need Sendkeys.

Public Sub Write_to_Text_File()
Dim strOne As String
Dim strTwo As String
Dim strThree As String
Dim RetVal

strOne = "I DO NOT want the hassle of writing to a file"
strTwo = "I DO NOT want to write to a report"
strThree = "I DO NOT want to write to a form"

Open "C:\MyFile.txt" For Output As #1 ' Open file for output.

''Write on separate lines
Write #1, strOne ' Write delimited data.
Write #1, strTwo
Write #1, strThree

''OR Write on one line as comma-delimited data
Write #1, ' Write blank line.
Write #1, ' Write blank line.
Write #1, strOne, strTwo, strThree

Close #1 ' Close file.

RetVal = Shell("C:\WINDOWS\Notepad.EXE C:\MyFile.txt", 1)

End Sub

Rick

Vmusic wrote: Hi,
I am trying to write out an array of string variables to Notepad. I
can't get SendKeys to accept the string variable only literal quoted
strings.

I DO NOT want the hassle of writing to a file
I DO NOT want to write to a report
I DO NOT want to write to a form

My user requires I write this array of string variables out to Notepad,
and that I leave Notepad open. (They will be copying these strings and
pasting them into another application)

I tried three quotes and then the variable, but that didn't work

Dim strMyString As String 'Just one string I know
strMyString = "This is a string I want to output to Notepad"

'Then I opened notepad
SendKeys """ & strMyString & """ 'This doesn't work

Ahhhh.... Why is something so simple SO HARD

Any help is GREATLY appreciated
Vmusic


Mar 18 '06 #6
Business requirements aren't necessarily stupid.

Thank you Dr. Chao for your consideration, however your function adds
an extra quote character. I want to send ONLY the characters from the
variable. Your procedure below sends an additional begining and ending
quote
Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub

Mar 18 '06 #7
"Vmusic" <ak*****@irisicom.net> wrote in
news:11*********************@g10g2000cwb.googlegro ups.com:
Business requirements aren't necessarily stupid.
Nobody said that was the case. What is stupid is a programmer-
analyst who says "I dont want the hassle of writing to a file."

Thank you Dr. Chao for your consideration, however your
function adds an extra quote character. I want to send ONLY
the characters from the variable. Your procedure below sends
an additional begining and ending quote
Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub


--
Bob Quintal

PA is y I've altered my email address.
Mar 18 '06 #8
Vmusic wrote:
I want to send ONLY the characters from the
variable. Your procedure below sends an additional begining and ending
quote

Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub


Hello Vmusic,

I don't mean this in a nasty way, but given that the relatively simple
solution to the above has evaded you, I'm not sure if the following
alternative would be viable for you or not... but here it is anyway,
hopefully it will be of some help.

What about simply copying the contents of the variable to the clipboard?
I do this myself for, example, when a user wants to examine the SQL my
apps have generated in other places (for example, an Oracle SQL
statement to be examined in SQL Plus, Enterprise Manager, etc).

http://www.mvps.org/access/api/api0049.htm

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Mar 19 '06 #9
Sub TestSendkeys()
Dim retval
Dim strtxt As String
retval = Shell("Notepad.exe", 1)
strtxt = "Using Sendkeys can be dangerous..."
SendKeys strtxt
End Sub

Arno R

"Vmusic" <ak*****@irisicom.net> schreef in bericht news:11*********************@g10g2000cwb.googlegro ups.com...
Business requirements aren't necessarily stupid.

Thank you Dr. Chao for your consideration, however your function adds
an extra quote character. I want to send ONLY the characters from the
variable. Your procedure below sends an additional begining and ending
quote


Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub

Mar 19 '06 #10
On 18 Mar 2006 14:24:39 -0800, "Vmusic" <ak*****@irisicom.net> wrote:
Business requirements aren't necessarily stupid.

Thank you Dr. Chao for your consideration, however your function adds
an extra quote character. I want to send ONLY the characters from the
variable. Your procedure below sends an additional begining and ending
quote
Sub TestSendKeys()
Dim s As String
s = "A dumb thing to do."
SendKeys """" & s & """"
End Sub


You could use scripting, eg

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Notepad.exe"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "This is a test."

see http://www.microsoft.com/technet/scr....mspx?mfr=true

for further information on this type of thing including some (but not all) of the drawbacks.

Mar 19 '06 #11
Very handy. Thanks for the post.
May 25 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jesper | last post: by
1 post views Thread by Tim | last post: by
46 posts views Thread by Ian Boyd | last post: by
6 posts views Thread by aagarwal8 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.