VBA - Open XLS App On-Top of MSAccess

2019-08-20 07:55发布

I am creating and formatting an XLS Workbook from an Access Database using VBA, initiated via a user button press on a form.

I'd like to have the XLS App ALWAYS open on top of the AccessDB to permit the user to see the worksheet directly. Currently it is intermittent, XLS usually opens UNDER Access on first iteration, but then on-top in subsequent iterations in the same session. User review of the file is necessary prior to final save and export to our client portal. There will typically only be a single iteration per user session.

I am using the following approach (pseudo):

Dim appXLS As Object
Dim wbkNew As Object
Dim wks1, wks2, wks3 As Object

Set appXLS = CreateObject("Excel.Application")
Set wbkNew = appXLS.Workbooks.Add

appXLS.Visible = True
wbkNew.Activate

...populate & format 3 worksheets from Access

wks1.Activate  ' go back to sheet 1
wbkNew.SaveAs AccessMode:=xlExclusive, FileName:=myFile

I am saving the file in this routine, so any "overwrite file" warnings also open under MSAccess.

I thought the .Activate lines would ensure the desired function. Any thoughts or ideas on this?

Thanks!

0条回答
登录 后发表回答