Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
I am having issues with this code working and not completely working. its a 50 50 chance that the file remains open. Sometimes when executing the code via button click in access it executes WITH OUT excel remaining visible and thus puts one of those faded ~"filename" icons on my desktop signifying that excel is open but not visible even those i am specifying it int he code to be visible.
is there a slightly different way i should be opening excel in order to perform this? the transferspeadsheet works perfectly and does not overwrite the other tabs in the file i just wish it would open reliably.
is there a slightly different way i should be opening excel in order to perform this? the transferspeadsheet works perfectly and does not overwrite the other tabs in the file i just wish it would open reliably.
VBA Code:
Private Sub Qualitymetrics_Click()
'Declare stuff
Dim excelapp As Object
Dim wb As Object
Dim openpath As String
openpath = "C:\users\desktop\ComplaintMetricsQuery.xlsx" 'Set file path
Set excelapp = CreateObject("Excel.Application")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "ComplaintMetricsQuery", "C:\users\desktop\ComplaintMetricsQuery.xlsx", True
Set wb = Excel.Workbooks.Open(openpath)
excelapp.Visible = True
'wb.worksheets("QueryDump").Range("A1:K100").ClearContents
wb.Save
'wb.Close
End Sub