Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetParent disables part of child functionality

Status
Not open for further replies.

wvandenberg

Technical User
Oct 24, 2002
125
CA
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.


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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top