Switching between Word & Excel '97 - problem

G

grasping@straws

The following code works in Word (from a toolbar button) to switch
from the
open Word document to the open Excel worksheet (& then run an Excel
macro to
paste into a cell).

----------------------------------------------------------------------------

Sub CopyToExcel()
'
'
Dim xlObj As Object
Selection.Copy
Set xlObj = GetObject(, "Excel.Application")
xlObj.Visible = True
xlObj.Run "PasteTab"
Set xlObj = Nothing

End Sub
----------------------------------------------------------------------------
Tried a variation of same (as below, using "wdrObj" instead of "xlObj"
throughout),
tied to a Worksheet_SelectionChange (ByVal, TargetAsRange) event - so
it
would switch back to the open Word document for the next selection -
but it
wouldn't work. Why not?
----------------------------------------------------------------------------
Sub SwitchToWordl()
'
'
Dim wrdObj As Object
Set wrdObj = GetObject(, "Word.Application")
wrdObj.Visible = True
Set wrdObj = Nothing

End Sub
 
D

Dave Peterson

maybe just:

Option Explicit
Sub SwitchToWordl()
AppActivate "Microsoft Word"
End Sub

Would work ok.

Any chance you could just modify your excel paste macro so that it's
incorporated in the MSWord code?

Then you wouldn't actually leave MSWord.
 
D

Dave Peterson

And if you want to try it:

Option Explicit
Sub SwitchToExcel()
AppActivate "Microsoft Excel"
End Sub
 
G

grasping@straws

maybe just:

Option Explicit
Sub SwitchToWordl()
AppActivate "Microsoft Word"
End Sub

Would work ok.

Whoa..way too simple! (Heh)
Thanks once again, Dave!

tm
 

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