wvandenberg
Technical User
Hello,
I am trying to load a selected Excel workbook into an Access subform that is on an Access form. I want to be able to select information in the spreadsheet then send it back to my main form and use it for processing. I have it working so that the Excel application and workbook both load into the subform but I am unable to click on a cell and edit the information, select a row or column or use the scroll bars. Ideally, I would only like to display only the workbook portion of the Excel window so I can select rows, columns and cells.
If anyone could give me some advice I would really appreciate it. Here is the code I'm using.
Thanks,
Wendy
I am trying to load a selected Excel workbook into an Access subform that is on an Access form. I want to be able to select information in the spreadsheet then send it back to my main form and use it for processing. I have it working so that the Excel application and workbook both load into the subform but I am unable to click on a cell and edit the information, select a row or column or use the scroll bars. Ideally, I would only like to display only the workbook portion of the Excel window so I can select rows, columns and cells.
If anyone could give me some advice I would really appreciate it. Here is the code I'm using.
Code:
Option Compare Database
Option Explicit
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As Long
Sub WorkOnAWorkbook()
Dim appExcel As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim bool As Boolean
Dim strFile As String
Dim strWbName As String
Dim wbk As Long
strFile = Get_ExcelLocation("")
On Error Resume Next
Set appExcel = GetObject(, "Excel.Application")
If Err Then
bool = True 'Excel was not running
Set appExcel = New Excel.Application
End If
On Error GoTo Err_Handler
Set wb = appExcel.Workbooks.Open(FileName:=strFile)
strWbName = Mid(strFile, InStrRev(strFile, "\") + 1, (Len(strFile) - 3) - (InStrRev(strFile, "\") + 1))
SetParent appExcel.hWnd, sfrXL.Form.hWnd
Set ws = wb.Sheets(1)
ws.Select
ws.Activate
appExcel.Visible = True
Exit Sub
Err_Handler:
MsgBox strFile & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
If bool Then
appExcel.Quit
End If
End Sub
Thanks,
Wendy