Activate Excel Window Upon Export from Access

S

SMT

I want to make the Excel window the active window upon export from Access.
Wasnt sure what code to use and where to put it (Excel or Access) Below I
have included both the code for the export out of Access and the code that I
have in Excel. Any help would be appreciated. Right now after I hit the
export button the dialog box that allows the user to select a folder appears
in the background behind Access window.

Export button in Access

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "qryGraphExportStep4Dept", _
"\\naeanrfkfs27\C163\Navsea_inhd_nswc03\C6\Shared\CompleteAndOnTime\qryGraphExportStep4.xlt", , "qryGraphExportStep4"
Application.FollowHyperlink
"\\naeanrfkfs27\C163\Navsea_inhd_nswc03\C6\Shared\CompleteAndOnTime\qryGraphExportStep4.xlt"

_______
Auto_open macro in excel file

If Application.ActiveWorkbook.Name <> (Range("R1").Value & "_" &
Range("Q1").Value & "_" & Format(Date, "mmdd") & ".xls") Then
MsgBox "Please select the folder in which to save your file. You do not
need to add a file name. A file name will be generate automatically using
Reporting Area, Customer Type, and Todays Date as the file name."
' Open the file dialog
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = Environ("USERPROFILE") & "\"
.Show
mydir = .SelectedItems(1)
End With

If Len(mydir) = 0 Then mydir = "C:"
If Mid(mydir, Len(mydir), 1) = "\" Then mydir = Left(mydir, Len(mydir) -
1)
ActiveWorkbook.SaveAs Filename:=mydir & "\" & Range("R1").Value & "_" &
Range("Q1").Value & "_" & Format(Date, "mmdd"),
FileFormat:=Excel.XlFileFormat.xlWorkbookNormal
MsgBox "Your file was saved to " & mydir & ". Reporting Area, Customer
Type, and Todays Date were used as the file name."
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top