Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm trying to consolidate data from the first worksheet
in one Excel file (the 'source' file - Book1.xls) into another (the 'opened' file - Book2.xls). To do so, I need the Range of the data in the source file. I have a 'LastCell' Function that finds the last row and the last cell having data on a worksheet and I want to use it on the source file. I've opened an Excel workbook and I have the following code under a button on a form. Private Sub CommandButton4_Click() Dim LastRow As Long, LastCol As Integer Dim wb As Workbook, ws as Worksheet Set wb = "C:\Documents and Settings\Dad\My Documents\Book1.xls Set ws = wb.Sheets(1) LastRow = LastCell(ws).Row LastCol = LastCell(ws).Column End Sub I can then use the LastRow,LastCol to set the Range on the source file. However, when I run the above code, I get a "Type Mismatch" error before the Subroutine code fires. If I change the 'set' statement to: Set wb = Book1.xls I get an "Object Required" error when the set statement fires. Can someone tell me the proper way to 'look into' an unopened Excel file to get the information I want? It may have something to do with the syntax I'm using to set the wb variable - I'm not sure. Thanks, Rick |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
vba syntax for excel object | Excel Discussion (Misc queries) | |||
Proper syntax for this | Excel Discussion (Misc queries) | |||
UDF not returning proper value - circular reference/multi workbook | Setting up and Configuration of Excel | |||
proper syntax order | Excel Worksheet Functions | |||
need help with syntax of a Workbook Event | Excel Programming |