Newbie trying to open Excel in foreground from form

mattewsearle79

New member
Local time
Today, 07:52
Joined
Sep 29, 2016
Messages
2
Hi

I'm relatively new to using VBA. I've put in the below code to open an excel spreadsheet from access but when I press the button the spreadsheet opens in the background rather than in front of access. How can I open the spreadsheet in the foreground? Please be gentle and explain where I would need to add to the code.


Private Sub Command0_Click()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = New Excel.Application
With xlApp
.UserControl = True
.Visible = True
.WindowState = Excel.XlWindowState.xlMaximized
Set xlWB = .Workbooks.Open("C:\Users\Public\Documents\Rota.xlsx", , False)
End With

End Sub

Thanks in advance.
 
Insert the below codeline:
Code:
xlWB.Activate
 
Thanks for the response JHB. Unless I'm inserting the code in the wrong place there was no change with that line of code.
 
Where did you insert it, show your code?
 
You could try...

Public Sub RunExcelMacro()
Dim wb1 As Object
Set wb1 = CreateObject("Excel.Application")
With wb1
.Workbooks.Open ("XLS path")
.Visible = True
End With
Set wb1 = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom