OLE switching <-> Apps

L

lance-news

I have some code to open a program. The problem is that when the
applicaton opens it becomes the active window. I need to have Excel
as the active window when the Sub is finished. How can I do this?

Lance



Sub Openfile()
Dim Varlist As String
'OPEN DIALOG BOX TO OPEN SPSSFILE
OFile = Application.GetOpenFilename("SPSS Datafile, *.sav")

'USE OLE TO OPEN SPSS
Set oApp = CreateObject("SPSS.Application")
Set oDoc = oApp.OpenDataDoc(OFile)
oDoc.Visible = True

'Another way to open file
'sCommands = "GET FILE = ' " & OFile & " ' "
'oApp.ExecuteCommands sCommands, True

'USE OLE TO OPEN OUTPUT DOC
Set oOut = oApp.NewOutputDoc

oOut.Visible = True
End Sub
 
K

Ken Dales

End your code with:
AppActivate "Microsoft Excel"
This will make Excel the active window (note: for more
specificity, e.g. if you have multiple Excel sessions
open, you may want to duplicate the exact title bar text
from your excel session).
 

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