J
John T Ingato
I have a form the opens an Excel file by use of a filedialog object. Excel
opens up, the file is opened also. some formatting is performed and the file
is resaved under a different name and close. One problem is, after the file
is closed, how do I close Excel?
Also , prior to performing any functions on the Excel file, I make sure the
file is a valid type of file. If its formatting is different then expected,
a meesagebox alert is sent. But since the excel application is active or has
the focus, the Access user cannot see the message without switching over.
Is there a way to return focus to the access window?
I threw in a quick fix at the bottom: excelApp.visible = False. But that
just hide it, right? And once the routine completes, I have lost any handles
to the Excel App, correct?
Code:
Dim fd As FileDialog 'Declare a variable as a FileDialog object.
Dim FileToOpen As Variant
Dim ExcelApp as Object
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
If .Show = -1 Then
FileToOpen = .SelectedItems.item(1)
Else
End If
End With
Set fd = Nothing
' Open The selected file
Set ExcelApp = CreateObject("Excel.Application")
With ExcelApp
.Visible = True
' Only XL 97 supports UserControl Property
On Error Resume Next
.UserControl = False
End With
Set OpenNew852 = ExcelApp.Workbooks.Open(FileToOpen)
ExcelApp.Visible = False
opens up, the file is opened also. some formatting is performed and the file
is resaved under a different name and close. One problem is, after the file
is closed, how do I close Excel?
Also , prior to performing any functions on the Excel file, I make sure the
file is a valid type of file. If its formatting is different then expected,
a meesagebox alert is sent. But since the excel application is active or has
the focus, the Access user cannot see the message without switching over.
Is there a way to return focus to the access window?
I threw in a quick fix at the bottom: excelApp.visible = False. But that
just hide it, right? And once the routine completes, I have lost any handles
to the Excel App, correct?
Code:
Dim fd As FileDialog 'Declare a variable as a FileDialog object.
Dim FileToOpen As Variant
Dim ExcelApp as Object
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
If .Show = -1 Then
FileToOpen = .SelectedItems.item(1)
Else
End If
End With
Set fd = Nothing
' Open The selected file
Set ExcelApp = CreateObject("Excel.Application")
With ExcelApp
.Visible = True
' Only XL 97 supports UserControl Property
On Error Resume Next
.UserControl = False
End With
Set OpenNew852 = ExcelApp.Workbooks.Open(FileToOpen)
ExcelApp.Visible = False