By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,077 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,077 IT Pros & Developers. It's quick & easy.

SendKey Commands

P: n/a
I have an issue where I have three Cases that SHOULD act the same but
don't. If you look at the code below you will see that the general
premise is to open a MSWord template and then use SendKey commands to
get it to save the file using a new name (NewFName is assigned earlier
in the code).

A couple of issues to keep in mind. These are MailMerge templates that
are attached to a Text Deliminted File (a separate one for each Case,
i.e. Agent.txt, Client.txt and Sales.txt respectively). The text files
were created in the same manner (exported from an Access query).
Start Code
----------------------------------------------------------
Select Case frmTempType
Case 1 'Agent
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewAgent.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 2 'Client
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewClient.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 3 'Sales
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewSales.dot", 1)
SendKeys "~" 'Confirms the import method of the text
file. Don't know why its not needed on the others.
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
End Select
----------------------------------------------------------
End Code

The problem is that for some reason when the Sales Case (Case 3 above)
is initiated a text conversion box appears when it attempts to open the
file asking for what kind of conversion that I want to perform and for
some reason it doesn't perform the rest of the SendKey commands
correctly. Anyone have any insights on why the SendKey commands would
work fine in Case 1 & 2 but not in Case 3 above?

von

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Automation is usually a much more flexible way to interact with Word.

<ba*********@sbcglobal.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have an issue where I have three Cases that SHOULD act the same but
don't. If you look at the code below you will see that the general
premise is to open a MSWord template and then use SendKey commands to
get it to save the file using a new name (NewFName is assigned earlier
in the code).

A couple of issues to keep in mind. These are MailMerge templates that
are attached to a Text Deliminted File (a separate one for each Case,
i.e. Agent.txt, Client.txt and Sales.txt respectively). The text files
were created in the same manner (exported from an Access query).
Start Code
----------------------------------------------------------
Select Case frmTempType
Case 1 'Agent
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewAgent.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 2 'Client
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewClient.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 3 'Sales
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewSales.dot", 1)
SendKeys "~" 'Confirms the import method of the text
file. Don't know why its not needed on the others.
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
End Select
----------------------------------------------------------
End Code

The problem is that for some reason when the Sales Case (Case 3 above)
is initiated a text conversion box appears when it attempts to open the
file asking for what kind of conversion that I want to perform and for
some reason it doesn't perform the rest of the SendKey commands
correctly. Anyone have any insights on why the SendKey commands would
work fine in Case 1 & 2 but not in Case 3 above?

von

Nov 13 '05 #2

P: n/a
Please be more specific. What do you mean by "Automation"? Isn't the
use of SendKeys commands an 'automation' technique?

von

MacDermott wrote:
Automation is usually a much more flexible way to interact with Word.

<ba*********@sbcglobal.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have an issue where I have three Cases that SHOULD act the same but don't. If you look at the code below you will see that the general
premise is to open a MSWord template and then use SendKey commands to get it to save the file using a new name (NewFName is assigned earlier in the code).

A couple of issues to keep in mind. These are MailMerge templates that are attached to a Text Deliminted File (a separate one for each Case, i.e. Agent.txt, Client.txt and Sales.txt respectively). The text files were created in the same manner (exported from an Access query).
Start Code
----------------------------------------------------------
Select Case frmTempType
Case 1 'Agent
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewAgent.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 2 'Client
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewClient.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 3 'Sales
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewSales.dot", 1)
SendKeys "~" 'Confirms the import method of the text
file. Don't know why its not needed on the others.
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
End Select
----------------------------------------------------------
End Code

The problem is that for some reason when the Sales Case (Case 3 above) is initiated a text conversion box appears when it attempts to open the file asking for what kind of conversion that I want to perform and for some reason it doesn't perform the rest of the SendKey commands
correctly. Anyone have any insights on why the SendKey commands would work fine in Case 1 & 2 but not in Case 3 above?

von


Nov 13 '05 #3

P: n/a
"Automation" is Microsoft's term for the technique by which you can open an
instance of another (usually Office) program and interact with it
programmatically.

For example, once you've opened an instance of Word, instead of sending keys
to display the File, Open menu, and entering a file name, you could execute
code something like this: (AIR CODE)
objWord.Documents.Open MyFileName

It's a technique which should be covered in any intermediate to advanced VBA
coding text.

HTH

<ba*********@sbcglobal.net> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Please be more specific. What do you mean by "Automation"? Isn't the
use of SendKeys commands an 'automation' technique?

von

MacDermott wrote:
Automation is usually a much more flexible way to interact with Word.

<ba*********@sbcglobal.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have an issue where I have three Cases that SHOULD act the same but don't. If you look at the code below you will see that the general
premise is to open a MSWord template and then use SendKey commands to get it to save the file using a new name (NewFName is assigned earlier in the code).

A couple of issues to keep in mind. These are MailMerge templates that are attached to a Text Deliminted File (a separate one for each Case, i.e. Agent.txt, Client.txt and Sales.txt respectively). The text files were created in the same manner (exported from an Access query).
Start Code
----------------------------------------------------------
Select Case frmTempType
Case 1 'Agent
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewAgent.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 2 'Client
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewClient.dot", 1)
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
Case 3 'Sales
intForm = Shell("C:\Program Files\Microsoft
Office\Office\Winword.exe " & "C:\TEMP\MailMerge\NewSales.dot", 1)
SendKeys "~" 'Confirms the import method of the text
file. Don't know why its not needed on the others.
SendKeys "%f" 'Calls up File Menu
SendKeys "a" 'Calls up SAVE AS command
SendKeys NewFName 'Inserts filename into the filename field
SendKeys "{TAB}" 'Tabs to SAVE button
SendKeys "{TAB}"
SendKeys "~" 'Confirms and initiates the save.
End Select
----------------------------------------------------------
End Code

The problem is that for some reason when the Sales Case (Case 3 above) is initiated a text conversion box appears when it attempts to open the file asking for what kind of conversion that I want to perform and for some reason it doesn't perform the rest of the SendKey commands
correctly. Anyone have any insights on why the SendKey commands would work fine in Case 1 & 2 but not in Case 3 above?

von

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.