OLE switching <-> Apps

  • Thread starter Thread starter lance-news
  • Start date Start date
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
 
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).
 
Back
Top