Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bring Excel window to foreground

299 views
Skip to first unread message

Keith Tizzard

unread,
Nov 30, 2021, 7:26:38 AM11/30/21
to
I create an Excel spreadsheet in VBA in Access the start of which is:
' Dim excelobj As Excel.Application
Dim excelobj As Object
Set excelobj = openExcel
With excelobj
.Workbooks.Add
.Visible = True

.ActiveWorkbook.Sheets(1).Select
.ActiveSheet.Name = "Invoice schedule"
.cells(1, 1).FormulaR1C1 = "Invoice Schedule Week Ending " & Format(Me.fromDate, "dd/mm/yyyy")
.cells(1, 1).Font.Bold = True

.cells(2, 1) = "Vehicle"
.cells(2, 2) = "Date"
.cells(2, 3) = "Contract number"
.cells(2, 4) = "Client"


All this works well. However I would like the Excel window to become the foreground window. How do I do this?

DoCmd.SelectObject does not handle this.

Ron Weiner

unread,
Nov 30, 2021, 9:42:15 AM11/30/21
to
on 11/30/2021, Keith Tizzard supposed :
I believe you can use the VBA command AppActivate to do this.

AppActivate Application.Caption

Rdub

Ron Paii

unread,
Nov 30, 2021, 11:09:54 AM11/30/21
to
Assuming you use "CreateObject" to open Excel.
i.e. Set excelobj = CreateObject("Excel.Application")

The only difference I see from my code is I set the spreadsheet visible to true at the end.

Keith Tizzard

unread,
Dec 1, 2021, 6:40:06 AM12/1/21
to
Thanks. That works a treat. Just what I wanted
0 new messages