Shell and AppActivate problem

D

Doug Sanders

Pardon me if I'm in the wrong group, please redirect me if so. I don't want
to cross post.

I'm trying to use code to copy a word document into text for importing into
Access. Running Access '97 and Word '97 at the client's location.

Code looks like this.

Dim MyAppID As String
MyAppID = Shell("WINWORD.EXE", vbNormalFocus) ' Run Microsoft Word.
AppActivate ("Microsoft Word")
SendKeys "%(f)" 'Open 'file function
SendKeys "o"
SendKeys "Iword.doc"
SendKeys "%(o)"
SendKeys "%(f)"
SendKeys "%(a)"
SendKeys "{TAB}"
SendKeys "{DOWN}"
SendKeys "{DOWN}"
SendKeys "{DOWN}"
SendKeys "s"
SendKeys "y"
SendKeys "y"
SendKeys "%(f)" 'Open 'file function
SendKeys "x"
SendKeys "%{F4}", True


It launches Word steps thru all the line doing nothing I can see and then at
the end closes Access, not Word.

It looks like the 'SendKeys' commands are being sent to Access, not Word.

I tried the example supplied in the help file, and it does the same thing.
Sample is:

ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I = 1 To 100 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=", True ' Get grand total.
SendKeys "%{F4}", True

What am I missing?

Thanks,

Doug Sanders
 
K

Klatuu

I will not be able to help with the specific details, but rather than the
approach you are taking, you could use automation to create an instance of
Word in Access and manipulate the Word Object Model. I personally don't have
much experience with the Word object model, but you should be able to find
the details. Using the Object explorer in the VBA editor would be helpful in
finding the methods and properties of the Word object.
 
D

Doug Sanders

Well, I figured it out.

A few minor code changes, but the big thing was that you can't single step
through the proceedure, which i was trying to do.
For any one interested, the code looks like this.

Dim MyAppID As String
MyAppID = Shell("WINWORD.EXE", vbNormalFocus) ' Run Microsoft Word.
AppActivate ("Microsoft Word")

SendKeys "%(f)", False
SendKeys "o", True
SendKeys "Iword", True
SendKeys "{ENTER}", True

SendKeys "%(f)", False
SendKeys "a", True
SendKeys "{TAB}", True

SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}"
SendKeys "{ENTER}", True
SendKeys "%(s)"
SendKeys "y", True
SendKeys "%(f)", True
SendKeys "x", True

Doug Sanders
 
J

John Nurick

This is simpler and a lot more robust:

Sub SaveWordDocAsText()
Dim oDoc As Object

Set oDoc = GetObject("C:\Folder\Filename.doc")
oDoc.SaveAs "C:\Folder\Filename.txt", 2 'wdFormatText
oDoc.Close False

End Sub
 
D

Doug Sanders

Thanks, works much better.


John Nurick said:
This is simpler and a lot more robust:

Sub SaveWordDocAsText()
Dim oDoc As Object

Set oDoc = GetObject("C:\Folder\Filename.doc")
oDoc.SaveAs "C:\Folder\Filename.txt", 2 'wdFormatText
oDoc.Close False

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top