ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OLE switching <- Apps (https://www.excelbanter.com/excel-programming/283171-ole-switching-apps.html)

[email protected]

OLE switching <- Apps
 
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


Ken Dales

OLE switching <- Apps
 
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).

-----Original Message-----
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

.



All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com