LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Proper syntax to Set a Workbook Object?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba syntax for excel object TKoel Excel Discussion (Misc queries) 1 February 10th 09 11:34 PM
Proper syntax for this Barb Reinhardt Excel Discussion (Misc queries) 1 August 4th 06 02:15 PM
UDF not returning proper value - circular reference/multi workbook Jeff Setting up and Configuration of Excel 1 February 1st 06 12:52 AM
proper syntax order Roberta H via OfficeKB.com Excel Worksheet Functions 2 January 18th 06 10:14 PM
need help with syntax of a Workbook Event Paul Simon[_2_] Excel Programming 3 July 30th 03 03:43 AM


All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"