Hi Everyone,
I have a function which I have written which allows a user to direct an Access database to an Excel file using the Dialogs(xlDialogOpen).show method. It returns the path to the file. Originally when I wrote it I had the problem that although the instance of Excel would show the dialog box, it would not be activated. I got around this by using the SendKeys command to send {ALT} {SHIFT} {TAB}, which moved the focus to the last application opened. This worked fine in Access 2000. I've just had 2002 installed on my machine, and it's suddenly stopped working! Here's my code, all suggestions gratefully received!
Function getExcel(strName As String) As Boolean
Dim objExcel As Excel.Application
Set objExcel = New Excel.Application
Dim wkbOpen As Workbook
Dim intResponse As Integer
intResponse = MsgBox("Please select the correct Excel File to access", vbOKCancel)
If intResponse = vbCancel Then GoTo Err_Trap
On Error GoTo Err_Trap
objExcel.Dialogs(xlDialogOpen).Show
SendKeys "%+{TAB}"
Set wkbOpen = objExcel.ActiveWorkbook
strName = wkbOpen.Path & "\" & wkbOpen.Name
On Error GoTo 0
wkbOpen.Close savechanges:=False
Set wkbOpen = Nothing
objExcel.Quit
Set objExcel = Nothing
getExcel = True
Exit Function
Err_Trap:
getExcel = False
End Function
I have a function which I have written which allows a user to direct an Access database to an Excel file using the Dialogs(xlDialogOpen).show method. It returns the path to the file. Originally when I wrote it I had the problem that although the instance of Excel would show the dialog box, it would not be activated. I got around this by using the SendKeys command to send {ALT} {SHIFT} {TAB}, which moved the focus to the last application opened. This worked fine in Access 2000. I've just had 2002 installed on my machine, and it's suddenly stopped working! Here's my code, all suggestions gratefully received!
Function getExcel(strName As String) As Boolean
Dim objExcel As Excel.Application
Set objExcel = New Excel.Application
Dim wkbOpen As Workbook
Dim intResponse As Integer
intResponse = MsgBox("Please select the correct Excel File to access", vbOKCancel)
If intResponse = vbCancel Then GoTo Err_Trap
On Error GoTo Err_Trap
objExcel.Dialogs(xlDialogOpen).Show
SendKeys "%+{TAB}"
Set wkbOpen = objExcel.ActiveWorkbook
strName = wkbOpen.Path & "\" & wkbOpen.Name
On Error GoTo 0
wkbOpen.Close savechanges:=False
Set wkbOpen = Nothing
objExcel.Quit
Set objExcel = Nothing
getExcel = True
Exit Function
Err_Trap:
getExcel = False
End Function