Activating EXCEL window from PowerPoint

B

Barb Reinhardt

I have this snippet of code that I suspect needs to be modified. I'm running
this out of PowerPoint and need to know how to get Excel to activate so that
it's not out there waiting for me to make a workbook selection. Can someone
assist?

Thanks

Sub OpenExcelWorkbook(myWB As Excel.Workbook, WorkbookIsOpen As Boolean)
Dim XLApp As Excel.Application

Set XLApp = Nothing
On Error Resume Next
Set XLApp = GetObject(, "Excel.Application")
On Error GoTo 0
If XLApp Is Nothing Then
Set XLApp = CreateObject("Excel.Application")
XLApp.visible = True
End If

' Suspect I need something here to activate Excel

With XLApp.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", "*.xls"
.FilterIndex = 1
.Title = "Please Select Workbook to open"
If .Show = False Then Exit Sub
sFile = .SelectedItems(1)
End With

Application.Activate

ShortName = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))

On Error Resume Next
Set myWB = Nothing
Set myWB = XLApp.Workbooks(ShortName)
On Error GoTo 0

If myWB Is Nothing Then
Set myWB = XLApp.Workbooks.Open(sFile, False) 'Opening to modify
WorkbookIsOpen = False
Else
WorkbookIsOpen = True
End If

End Sub
 

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