NascarBaritone
Registered User.
- Local time
- Today, 05:39
- Joined
- Sep 23, 2008
- Messages
- 75
Long story short: I have a macro that I run in Excel that copies, pastes, filters and then opens an Access database that I then want to import and produce a report.
When Access opens I want to get a file dialog asking what Excel file the user wants to import. However, I first want to close the active Excel window. The database opens with an Autoexec macro that calls the following module:
The file dialog opens, but the Excel application doesn't close. If I cancel the file dialog box THEN the Excel application closes. However, if shorten the code to just close Excel like below...it closes just fine.
I have a feeling it is relatively obvious, but I can't seem to figure it out.
When Access opens I want to get a file dialog asking what Excel file the user wants to import. However, I first want to close the active Excel window. The database opens with an Autoexec macro that calls the following module:
Code:
Option Compare Database
Function OpenDB() As String
Dim dlg As FileDialog
Dim StrFileName As String
DoCmd.RunCommand acCmdAppMinimize
'Open Excel and make visible
Set o = GetObject(, "Excel.Application")
o.Visible = True
o.DisplayAlerts = False
o.Quit
o.DisplayAlerts = True
Set o = Nothing
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.Title = "Select the Excel file to import"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel CSV Files", "*.csv", 1
.Filters.Add "Excel Files", "*.xls", 2
.Filters.Add "All Files", "*.*", 3
If .Show = -1 Then
StrFileName = .SelectedItems(1)
DoCmd.TransferText acImportDelim, "tblCheckLog", StrFileName, True
DoCmd.OpenForm "FormDialog"
End If
End With
End Function
The file dialog opens, but the Excel application doesn't close. If I cancel the file dialog box THEN the Excel application closes. However, if shorten the code to just close Excel like below...it closes just fine.
Code:
Option Compare Database
Function OpenDB() As String
DoCmd.RunCommand acCmdAppMinimize
'Open Excel and make visible
Set o = GetObject(, "Excel.Application")
o.Visible = True
o.DisplayAlerts = False
o.Quit
o.DisplayAlerts = True
Set o = Nothing
End Function
I have a feeling it is relatively obvious, but I can't seem to figure it out.