• Bring Excel window to foreground

    From Keith Tizzard@21:1/5 to All on Tue Nov 30 04:26:36 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron Weiner@21:1/5 to All on Tue Nov 30 09:42:07 2021
    on 11/30/2021, Keith Tizzard supposed :
    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.

    I believe you can use the VBA command AppActivate to do this.

    AppActivate Application.Caption

    Rdub

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ron Paii@21:1/5 to Keith Tizzard on Tue Nov 30 08:09:51 2021
    On Tuesday, November 30, 2021 at 6:26:38 AM UTC-6, Keith Tizzard wrote:
    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.

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Tizzard@21:1/5 to Ron Weiner on Wed Dec 1 03:40:02 2021
    Thanks. That works a treat. Just what I wanted


    On Tuesday, 30 November 2021 at 14:42:15 UTC, Ron Weiner wrote:
    on 11/30/2021, Keith Tizzard supposed :
    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.
    I believe you can use the VBA command AppActivate to do this.

    AppActivate Application.Caption

    Rdub

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)