Controlling other programs and pasting the results into Excel

3 views
Skip to first unread message

Ron Fritz

unread,
Dec 10, 1997, 3:00:00 AM12/10/97
to

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01BD05BE.B5AD4AC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I was playing around with control of other programs, in this case =
"Calculator" and the use of SendKeys. The following code loads =
Calculator fine, copies the result from Calculator to the clipboard =
fine, but elicits odd behavior when pasting the result into Excel. If I =
send Ctrl-V to Excel, it pastes the Clipboard into the active cell. But =
if I send a second Ctrl-V to Excel, only the second paste command is =
executed. Likewise if I follow the first Ctrl-V with =
"ActiveSheet.Paste", only this second paste command is executed. (See my =
comment in the code below).=20

Here is the code which was basically copied from the Microsoft Excel VBA =
Help File:

Sub test()
r =3D Shell("C:\WINDOWS\CALC.EXE", 1)
AppActivate r ' Activate the Calculator.
For I =3D 1 To 10 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=3D", True ' Get grand total.
SendKeys "^c"
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
AppActivate "Microsoft Excel"
Worksheets(1).Activate

'This is the code which I added. I would expect that, if the active =
cell in Sheet1 were "A1", then the result of the calculations in =
Calculator would be copied into "A1", "A3", and "A5". But, they aren't. =
They are only copied into "A5".

SendKeys "^v"
ActiveCell.Offset(2, 0).Select
SendKeys "^v"
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

End Sub


------=_NextPart_000_0007_01BD05BE.B5AD4AC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>I was playing around with control of other programs, =
in this=20
case &quot;Calculator&quot; and the use of SendKeys.&nbsp; The following =
code=20
loads Calculator fine, copies the result from Calculator to the =
clipboard fine,=20
but elicits odd behavior when pasting the result into Excel.&nbsp; If I =
send=20
Ctrl-V to Excel, it pastes the Clipboard into the active cell.&nbsp; But =
if I=20
send a second Ctrl-V to Excel, only the second paste command is =
executed.&nbsp;=20
Likewise if I follow the first Ctrl-V with =
&quot;ActiveSheet.Paste&quot;, only=20
this second paste command is executed. (See my comment in the code =
below).=20
</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Here is the code which was basically copied from the =
Microsoft=20
Excel VBA Help File:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Sub test()<BR>r =3D =
Shell(&quot;C:\WINDOWS\CALC.EXE&quot;,=20
1)<BR>AppActivate r&nbsp;&nbsp;&nbsp;&nbsp; ' Activate the =
Calculator.<BR>For I=20
=3D 1 To 10&nbsp;&nbsp;&nbsp; ' Set up counting =
loop.<BR>&nbsp;&nbsp;&nbsp;=20
SendKeys I &amp; &quot;{+}&quot;, True&nbsp;&nbsp;&nbsp; ' Send =
keystrokes to=20
Calculator<BR>Next I&nbsp; ' to add each value of I.<BR>SendKeys =
&quot;=3D&quot;,=20
True&nbsp; ' Get grand total.<BR>SendKeys =
&quot;^c&quot;</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>SendKeys &quot;%{F4}&quot;, True&nbsp; ' Send ALT+F4 =
to close=20
Calculator.<BR>AppActivate &quot;Microsoft=20
Excel&quot;<BR>Worksheets(1).Activate</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT color=3D#0000ff face=3D"">'This is the code =
which I=20
added.&nbsp; I would expect that, if the active cell in Sheet1 were=20
&quot;A1&quot;, then the result of the calculations in Calculator would =
be=20
copied into &quot;A1&quot;, &quot;A3&quot;, and &quot;A5&quot;.&nbsp; =
But, they=20
aren't.&nbsp; They are only copied into =
&quot;A5&quot;.</FONT></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>SendKeys &quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>SendKeys &quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>ActiveSheet.Paste</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>End Sub<BR></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0007_01BD05BE.B5AD4AC0--


Robert Sample

unread,
Dec 11, 1997, 3:00:00 AM12/11/97
to

This is a multi-part message in MIME format.

------=_NextPart_000_027C_01BD0670.501020E0


Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Ron,

Since the data is coming in from another application, you should use the =
PasteSpecial Method for DialogSheet or Worksheet. Here is you code =
using that method and it works, the bit in blue is what I modified:

Sub UseCalculator()
Dim ReturnValue, I
ReturnValue =3D Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I =3D 1 To 100 ' Set up counting loop.


SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=3D", True ' Get grand total.

SendKeys "^c", True


SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
AppActivate "Microsoft Excel"

Range("A1").Select
ActiveSheet.PasteSpecial
ActiveCell.Offset(2, 0).Select
ActiveSheet.PasteSpecial
ActiveCell.Offset(2, 0).Select
ActiveSheet.PasteSpecial
End Sub


Ron Fritz wrote in message =
<#e8KgieB...@uppssnewspub05.moswest.msn.net>...


I was playing around with control of other programs, in this case =
"Calculator" and the use of SendKeys. The following code loads =
Calculator fine, copies the result from Calculator to the clipboard =
fine, but elicits odd behavior when pasting the result into Excel. If I =
send Ctrl-V to Excel, it pastes the Clipboard into the active cell. But =
if I send a second Ctrl-V to Excel, only the second paste command is =
executed. Likewise if I follow the first Ctrl-V with =
"ActiveSheet.Paste", only this second paste command is executed. (See my =
comment in the code below).=20
=20

Here is the code which was basically copied from the Microsoft Excel =
VBA Help File:
=20


Sub test()
r =3D Shell("C:\WINDOWS\CALC.EXE", 1)
AppActivate r ' Activate the Calculator.
For I =3D 1 To 10 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=3D", True ' Get grand total.

SendKeys "^c"=20


SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
AppActivate "Microsoft Excel"

Worksheets(1).Activate=20
=20


'This is the code which I added. I would expect that, if the active =
cell in Sheet1 were "A1", then the result of the calculations in =
Calculator would be copied into "A1", "A3", and "A5". But, they aren't. =
They are only copied into "A5".

=20


SendKeys "^v"
ActiveCell.Offset(2, 0).Select
SendKeys "^v"
ActiveCell.Offset(2, 0).Select

ActiveSheet.Paste=20
=20
End Sub
=20

------=_NextPart_000_027C_01BD0670.501020E0


Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =
HTML//EN">
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua"><FONT size=3D3>Hi=20
Ron,</FONT></FONT><FONT size=3D3></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua"><FONT =
size=3D3></FONT></FONT><FONT=20
size=3D3></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua" size=3D3>Since the data =
is coming in=20
from another application, you should use the PasteSpecial Method for =
DialogSheet=20
or Worksheet.&nbsp; Here is you code using that method and it works, the =
bit in=20
blue is what I modified:</FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua" =
size=3D3></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Book Antiqua">Sub UseCalculator()<BR>&nbsp;&nbsp; Dim =

ReturnValue, I<BR>&nbsp;&nbsp; ReturnValue =3D =
Shell(&quot;CALC.EXE&quot;,=20
1)&nbsp; ' Run Calculator.<BR>&nbsp;&nbsp; AppActivate=20
ReturnValue&nbsp;&nbsp;&nbsp; ' Activate the Calculator.<BR>&nbsp;&nbsp; =
For I =3D=20
1 To 100&nbsp; ' Set up counting loop.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

SendKeys I &amp; &quot;{+}&quot;, True&nbsp;&nbsp; ' Send keystrokes to=20
Calculator<BR>&nbsp;&nbsp; Next I&nbsp;&nbsp; ' to add each value of=20
I.<BR>&nbsp;&nbsp; SendKeys &quot;=3D&quot;, True&nbsp;&nbsp; ' Get =
grand=20
total.<BR>&nbsp;&nbsp; SendKeys &quot;^c&quot;, True<BR>&nbsp;&nbsp; =
SendKeys=20
&quot;%{F4}&quot;, True&nbsp; ' Send ALT+F4 to close =
Calculator.<BR>&nbsp;&nbsp;=20
AppActivate &quot;Microsoft Excel&quot;<BR><FONT =
color=3D#0000ff>&nbsp;&nbsp;=20
Range(&quot;A1&quot;).Select<BR>&nbsp;&nbsp;=20
ActiveSheet.PasteSpecial<BR>&nbsp;&nbsp; ActiveCell.Offset(2,=20
0).Select<BR>&nbsp;&nbsp; ActiveSheet.PasteSpecial<BR>&nbsp;&nbsp;=20
ActiveCell.Offset(2, 0).Select<BR>&nbsp;&nbsp;=20
ActiveSheet.PasteSpecial<BR></FONT>End Sub<BR></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua" =
size=3D3></FONT>&nbsp;</DIV>
<DIV>Ron Fritz<RFR...@AKORN.NET> wrote in message &lt;#<A=20
href=3D"mailto:e8KgieB...@uppssnewspub05.moswest.msn.net">e8KgieB9GA.=
2...@uppssnewspub05.moswest.msn.net</A>&gt;...</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">
<DIV><FONT size=3D2>I was playing around with control of other =
programs, in=20
this case &quot;Calculator&quot; and the use of SendKeys.&nbsp; The=20
following code loads Calculator fine, copies the result from =
Calculator to=20
the clipboard fine, but elicits odd behavior when pasting the result =
into=20
Excel.&nbsp; If I send Ctrl-V to Excel, it pastes the Clipboard into =
the=20
active cell.&nbsp; But if I send a second Ctrl-V to Excel, only the =
second=20
paste command is executed.&nbsp; Likewise if I follow the first =
Ctrl-V with=20
&quot;ActiveSheet.Paste&quot;, only this second paste command is =
executed.=20
(See my comment in the code below). </FONT></DIV>


<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>Here is the code which was basically copied from =
the=20
Microsoft Excel VBA Help File:</FONT></DIV>


<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Sub test()<BR>r =3D =
Shell(&quot;C:\WINDOWS\CALC.EXE&quot;,=20

1)<BR>AppActivate r&nbsp;&nbsp;&nbsp;&nbsp; ' Activate the=20
Calculator.<BR>For I =3D 1 To 10&nbsp;&nbsp;&nbsp; ' Set up counting =

loop.<BR>&nbsp;&nbsp;&nbsp; SendKeys I &amp; &quot;{+}&quot;,=20
True&nbsp;&nbsp;&nbsp; ' Send keystrokes to Calculator<BR>Next =
I&nbsp; ' to=20
add each value of I.<BR>SendKeys &quot;=3D&quot;, True&nbsp; ' Get =
grand=20
total.<BR>SendKeys &quot;^c&quot;</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>SendKeys &quot;%{F4}&quot;, True&nbsp; ' Send =
ALT+F4 to=20
close Calculator.<BR>AppActivate &quot;Microsoft=20


Excel&quot;<BR>Worksheets(1).Activate</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2><FONT color=3D#0000ff face=3D"">'This is the =
code which I=20


added.&nbsp; I would expect that, if the active cell in Sheet1 were=20

&quot;A1&quot;, then the result of the calculations in Calculator =
would be=20
copied into &quot;A1&quot;, &quot;A3&quot;, and =
&quot;A5&quot;.&nbsp; But,=20
they aren't.&nbsp; They are only copied into=20


&quot;A5&quot;.</FONT></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>SendKeys &quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>SendKeys &quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>ActiveSheet.Paste</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>End =
Sub<BR></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_027C_01BD0670.501020E0--


Ron Fritz

unread,
Dec 13, 1997, 3:00:00 AM12/13/97
to

This is a multi-part message in MIME format.

------=_NextPart_000_002E_01BD075B.E1A75460


Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Robert, I have since played around with this and discovered that =
I needed to add a "true" behind the "^v" to instruct Excel to wait until =
it has the focus (or whatever applications must wait for). I haven't =
tried your code yet, but it will work with a regular paste, IF the paste =
command is coded as... SendKeys "^v", True
Robert Sample wrote in message <66q2o6$ic5$1...@wbnws01.ne.highway1.com>...
Hi Ron,
=20
Since the data is coming in from another application, you should use =
the PasteSpecial Method for DialogSheet or Worksheet. Here is you code =


using that method and it works, the bit in blue is what I modified:

=20


Sub UseCalculator()
Dim ReturnValue, I
ReturnValue =3D Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I =3D 1 To 100 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=3D", True ' Get grand total.
SendKeys "^c", True
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
AppActivate "Microsoft Excel"
Range("A1").Select
ActiveSheet.PasteSpecial
ActiveCell.Offset(2, 0).Select
ActiveSheet.PasteSpecial
ActiveCell.Offset(2, 0).Select
ActiveSheet.PasteSpecial
End Sub

=20
=20


Ron Fritz wrote in message =
<#e8KgieB...@uppssnewspub05.moswest.msn.net>...
I was playing around with control of other programs, in this case =
"Calculator" and the use of SendKeys. The following code loads =
Calculator fine, copies the result from Calculator to the clipboard =
fine, but elicits odd behavior when pasting the result into Excel. If I =
send Ctrl-V to Excel, it pastes the Clipboard into the active cell. But =
if I send a second Ctrl-V to Excel, only the second paste command is =
executed. Likewise if I follow the first Ctrl-V with =
"ActiveSheet.Paste", only this second paste command is executed. (See my =
comment in the code below).=20
=20

Here is the code which was basically copied from the Microsoft =
Excel VBA Help File:


=20
Sub test()
r =3D Shell("C:\WINDOWS\CALC.EXE", 1)
AppActivate r ' Activate the Calculator.
For I =3D 1 To 10 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=3D", True ' Get grand total.
SendKeys "^c"=20
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
AppActivate "Microsoft Excel"
Worksheets(1).Activate=20
=20

'This is the code which I added. I would expect that, if the =
active cell in Sheet1 were "A1", then the result of the calculations in =


Calculator would be copied into "A1", "A3", and "A5". But, they aren't. =
They are only copied into "A5".
=20
SendKeys "^v"
ActiveCell.Offset(2, 0).Select
SendKeys "^v"
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste=20
=20
End Sub
=20

------=_NextPart_000_002E_01BD075B.E1A75460


Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =

HTML//EN"><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>Thanks Robert, I have since played =
around with=20
this and discovered that I needed to add a &quot;true&quot; behind the=20
&quot;^v&quot; to instruct Excel to wait until it has the focus (or =
whatever=20
applications must wait for).&nbsp; I haven't tried your code yet, but it =
will=20
work with a regular paste, IF the paste command is coded as... <FONT=20
color=3D#0000ff>SendKeys &quot;^v&quot;, True</FONT></FONT></DIV>


<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">

<DIV>Robert Sample<ROBERT...@NE.MEDIAONE.NET> wrote in message =
&lt;<A=20
=
href=3D"mailto:66q2o6$ic5$1...@wbnws01.ne.highway1.com">66q2o6$ic5$1@wbnws01=
.ne.highway1.com</A>&gt;...</DIV>


<DIV><FONT color=3D#000000 face=3D"Book Antiqua"><FONT size=3D3>Hi=20
Ron,</FONT></FONT><FONT size=3D3></FONT></DIV>

<DIV><FONT color=3D#000000 face=3D"Book Antiqua"><FONT=20
size=3D3></FONT></FONT><FONT size=3D3></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua" size=3D3>Since the =
data is coming=20
in from another application, you should use the PasteSpecial Method =
for=20
DialogSheet or Worksheet.&nbsp; Here is you code using that method =
and it=20
works, the bit in blue is what I modified:</FONT></DIV>


<DIV><FONT color=3D#000000 face=3D"Book Antiqua" =
size=3D3></FONT>&nbsp;</DIV>

<DIV><FONT face=3D"Book Antiqua">Sub UseCalculator()<BR>&nbsp;&nbsp; =
Dim=20


ReturnValue, I<BR>&nbsp;&nbsp; ReturnValue =3D =
Shell(&quot;CALC.EXE&quot;,=20
1)&nbsp; ' Run Calculator.<BR>&nbsp;&nbsp; AppActivate=20

ReturnValue&nbsp;&nbsp;&nbsp; ' Activate the =
Calculator.<BR>&nbsp;&nbsp; For=20
I =3D 1 To 100&nbsp; ' Set up counting =
loop.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
SendKeys I &amp; &quot;{+}&quot;, True&nbsp;&nbsp; ' Send keystrokes =


to=20
Calculator<BR>&nbsp;&nbsp; Next I&nbsp;&nbsp; ' to add each value of =

I.<BR>&nbsp;&nbsp; SendKeys &quot;=3D&quot;, True&nbsp;&nbsp; ' Get =


grand=20
total.<BR>&nbsp;&nbsp; SendKeys &quot;^c&quot;, True<BR>&nbsp;&nbsp; =

SendKeys &quot;%{F4}&quot;, True&nbsp; ' Send ALT+F4 to close=20
Calculator.<BR>&nbsp;&nbsp; AppActivate &quot;Microsoft =
Excel&quot;<BR><FONT=20
color=3D#0000ff>&nbsp;&nbsp; =


Range(&quot;A1&quot;).Select<BR>&nbsp;&nbsp;=20
ActiveSheet.PasteSpecial<BR>&nbsp;&nbsp; ActiveCell.Offset(2,=20
0).Select<BR>&nbsp;&nbsp; ActiveSheet.PasteSpecial<BR>&nbsp;&nbsp;=20
ActiveCell.Offset(2, 0).Select<BR>&nbsp;&nbsp;=20
ActiveSheet.PasteSpecial<BR></FONT>End Sub<BR></FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"Book Antiqua" =
size=3D3></FONT>&nbsp;</DIV>
<DIV>Ron Fritz<RFR...@AKORN.NET> wrote in message &lt;#<A=20

=


href=3D"mailto:e8KgieB...@uppssnewspub05.moswest.msn.net">e8KgieB9GA.=
2...@uppssnewspub05.moswest.msn.net</A>&gt;...</DIV>
<BLOCKQUOTE=20

style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; =
PADDING-LEFT: 5px">


<DIV><FONT size=3D2>I was playing around with control of other =

programs,=20
in this case &quot;Calculator&quot; and the use of =


SendKeys.&nbsp; The=20
following code loads Calculator fine, copies the result from =

Calculator=20
to the clipboard fine, but elicits odd behavior when pasting the =
result=20
into Excel.&nbsp; If I send Ctrl-V to Excel, it pastes the =
Clipboard=20
into the active cell.&nbsp; But if I send a second Ctrl-V to =
Excel, only=20
the second paste command is executed.&nbsp; Likewise if I follow =
the=20
first Ctrl-V with &quot;ActiveSheet.Paste&quot;, only this =
second paste=20
command is executed. (See my comment in the code below). =


</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>Here is the code which was basically copied =
from the=20


Microsoft Excel VBA Help File:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>Sub test()<BR>r =3D=20
Shell(&quot;C:\WINDOWS\CALC.EXE&quot;, 1)<BR>AppActivate=20
r&nbsp;&nbsp;&nbsp;&nbsp; ' Activate the Calculator.<BR>For I =
=3D 1 To=20


10&nbsp;&nbsp;&nbsp; ' Set up counting =

loop.<BR>&nbsp;&nbsp;&nbsp;=20
SendKeys I &amp; &quot;{+}&quot;, True&nbsp;&nbsp;&nbsp; ' Send=20
keystrokes to Calculator<BR>Next I&nbsp; ' to add each value of=20
I.<BR>SendKeys &quot;=3D&quot;, True&nbsp; ' Get grand =
total.<BR>SendKeys=20


&quot;^c&quot;</FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>SendKeys &quot;%{F4}&quot;, True&nbsp; ' =
Send ALT+F4=20
to close Calculator.<BR>AppActivate &quot;Microsoft=20


Excel&quot;<BR>Worksheets(1).Activate</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT color=3D#0000ff face=3D"">'This is the =
code which I=20

added.&nbsp; I would expect that, if the active cell in Sheet1 =
were=20
&quot;A1&quot;, then the result of the calculations in =
Calculator would=20
be copied into &quot;A1&quot;, &quot;A3&quot;, and =
&quot;A5&quot;.&nbsp;=20
But, they aren't.&nbsp; They are only copied into=20


&quot;A5&quot;.</FONT></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>SendKeys =


&quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>SendKeys &quot;^v&quot;<BR>ActiveCell.Offset(2,=20
0).Select<BR>ActiveSheet.Paste</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>

<DIV><FONT size=3D2>End=20
Sub<BR></FONT>&nbsp;</DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_002E_01BD075B.E1A75460--


Reply all
Reply to author
Forward
0 new messages