I would like to be able to close Excel after queries have run and sheet has been written to. A portion of the code I use to open and write is below. Once the cells have been written I would like the file dialog box to open with a hard coded path that also allows user to change. Any ideas? Second code snippet is one way I have been trying, but not able to get it to work.
Code:
Dim objXL As Object
Dim objWB As Object
Dim objWS As Object
Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.Workbooks.Open("L:\DS\Data Services\Metrics\Dashboard\Dashboard_v1001.xlsx")
Set objWS = objWB.worksheets("DashBoard")
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim queryName As String
With objWS
'Cells(row,column)
.Cells(6, 2).Value = rsCount_Missing_LLC
.Cells(6, 3).Value = rsCount_Missing_LLC
End With
Code:
Dim dlgSaveAs As FileDialog
Dim strFilePath As String
Dim strFileName As String
Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
dlgSaveAs.Show
strFilePath = dlgSaveAs.SelectedItems("L:\DS\Data Services\Metrics\Dashboard\Dashboard_v1001.xlsx")
strFileName = Right(strFilePath, Len(strFilePath) - InStrRev(strFilePath, "\"))
strFilePath = Left(strFilePath, InStrRev(strFilePath, "\"))