AppActivate problem

P

paVBAuser

I'm trying to get the following code to launch Microsoft Word using the
AppActivate method and then return to the orginal workbook. I run the code
by calling Sub Primary which activates UserForm1 which then calls Sub
Secondary.

Sub Primary()
UserForm1.Show 'to display program running message
End Sub

Private Sub UserForm_Activate()
Secondary
Unload Me
End Sub

Sub Secondary()
Dim WordID As String, ExcelID As String
WordID = Shell("C:\Program Files\Microsoft
Office\Office\WINWORD.EXE", 1)
ExcelID = Shell("C:\Program Files\Microsoft
Office\Office\EXCEL.EXE", 1)
On Error GoTo WordError
AppActivate WordID
MsgBox "Word has been activated."
GoTo ResumeExcel
WordError:
MsgBox "Word error"
Exit Sub
ResumeExcel:
On Error GoTo ExcelError
AppActivate ExcelID
MsgBox "Excel has been reactivated."
GoTo EndSub
ExcelError:
MsgBox "Excel error"
Exit Sub
EndSub:
MsgBox "Resume Excel"
End Sub

The program yields an open Word Doc, focus set to a new instance of Excel
(and a new workbook) and a blinking Excel icon in the taskbar (reflecting the
original instance of Excel). Focus is returned to the original workbook when
I click on its icon (in the taskbar). The message "Word error" is displayed
when focus is returned to the original workbook.

Any help will be greately appreciated


Thanks much.
 
J

Joel

Here is where winword.exe is located on my PC

C:\Program Files\Microsoft Office\OFFICE11

do a search for windword.exe and check its location
 
K

Kevin

Thanks for the quick reply Joel and for reminding me to verify the path to
WINWORD. I'm using Office 2000 and the path reflected in my code is correct.
 
D

Dave D-C

WordID and ExcelID must be Long, not String.

paVBAuser said:
..
Dim WordID As String, ExcelID As String
WordID = Shell("C:\Program Files\Microsoft
Office\Office\WINWORD.EXE", 1)
ExcelID = Shell("C:\Program Files\Microsoft
Office\Office\EXCEL.EXE", 1)
..
 

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