O
Ogier
Hi out there!
In a thead started om May 30 I asked how to insert dummy text using the
=rand(.,.) statement.
Dough Robbins replied:
"Running a macro with the following code:
Selection.TypeText "=RAND(5,7)"
SendKeys "~"
on a machine with Vista Business and Word 2007 results in the following at
the location of the selection:
On the Insert tab, the galleries include items that are designed to
coordinate with the overall look of your document. You can use these
[etcetera]".
(This is the kind of result I want!)
Graham Mayor responded:
"The userform is the active window when you run this macro.
Sendkeys works in the active window.
You would need to dismiss the userform first eg
Private Sub CommandButtonInsertDummyText_Click()
Me.Hide
Selection.TypeText "=RAND(5,7)"
SendKeys "~"
End Sub"
I cannot make any of these suggestions work (using Word 2007 on a XP Prof
machine and calling the sub from a user form).
Using Dough's version I get, as I noted earlier, an infinite loop printing
"=RAND(5,7)".
Using Graham's version results in the text "RAND(5,7)" being written in the
document and a carriage return being inserted in the VB source code at the
position of the cursor. Switching the first two lines has the same effect.
I tried to add "Me.Show" after the line with SendKeys (in order to have a
symmetric situation) but this resulted in a "Out of stack space" sitiation.
I presume that "Me" refers to the user form, but the hiding seems not to work.
How come Dough Robbins' version can manage without the "Me"-statement?
Any furthers suggestions to make this work?
Best regards
Holger Nielsen
In a thead started om May 30 I asked how to insert dummy text using the
=rand(.,.) statement.
Dough Robbins replied:
"Running a macro with the following code:
Selection.TypeText "=RAND(5,7)"
SendKeys "~"
on a machine with Vista Business and Word 2007 results in the following at
the location of the selection:
On the Insert tab, the galleries include items that are designed to
coordinate with the overall look of your document. You can use these
[etcetera]".
(This is the kind of result I want!)
Graham Mayor responded:
"The userform is the active window when you run this macro.
Sendkeys works in the active window.
You would need to dismiss the userform first eg
Private Sub CommandButtonInsertDummyText_Click()
Me.Hide
Selection.TypeText "=RAND(5,7)"
SendKeys "~"
End Sub"
I cannot make any of these suggestions work (using Word 2007 on a XP Prof
machine and calling the sub from a user form).
Using Dough's version I get, as I noted earlier, an infinite loop printing
"=RAND(5,7)".
Using Graham's version results in the text "RAND(5,7)" being written in the
document and a carriage return being inserted in the VB source code at the
position of the cursor. Switching the first two lines has the same effect.
I tried to add "Me.Show" after the line with SendKeys (in order to have a
symmetric situation) but this resulted in a "Out of stack space" sitiation.
I presume that "Me" refers to the user form, but the hiding seems not to work.
How come Dough Robbins' version can manage without the "Me"-statement?
Any furthers suggestions to make this work?
Best regards
Holger Nielsen