Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default How do I access a sheet in another workbook using VBA?

Greetings everyone!

How do I access a sheet in another workbook?

Currently, I do the cheesie method of referencing it from within the cell,
but I always have to over copy the rows since I don't know when I've reached
the last non-empty row.

I want to be able to write some VBA code that will loop thru the sheet in
one workbook and write the info into a sheet in another work.

Thanks as Always!

Kurt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default How do I access a sheet in another workbook using VBA?

Without knowing more about what you wnat to copy here is a strat for you...

Sub Test()
Dim wbkSource As Workbook
Dim wbkDestination As Workbook
Dim wksSource As Worksheet
Dim wksDestination As Worksheet
Dim rngSource As Range
Dim rngDestination As Range

'Set your source
Set wbkSource = ThisWorkbook
Set wksSource = wbkSource.Sheets("Sheet1")
Set rngSource = wksSource.Cells

'Set your destination
On Error GoTo OpenBook
Set wbkDestination = Workbooks("ThatBook.xls")
On Error GoTo 0
Set wksDestination = wbkDestination.Sheets("Sheet1")
Set rngDestination = wksDestination.Range("A1")

'You now have all of your souce and destination objects

rngSource.Copy rngDestination

Exit Sub

OpenBook:
Set wbkDestination = Workbooks.Open("C:\Thatbook.xls")
Resume Next
Exit Sub

End Sub

--
HTH...

Jim Thomlinson


"kurt" wrote:

Greetings everyone!

How do I access a sheet in another workbook?

Currently, I do the cheesie method of referencing it from within the cell,
but I always have to over copy the rows since I don't know when I've reached
the last non-empty row.

I want to be able to write some VBA code that will loop thru the sheet in
one workbook and write the info into a sheet in another work.

Thanks as Always!

Kurt

Reply
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
Linking workbook and range protected Excel sheet to Access richiverse718 Excel Discussion (Misc queries) 0 March 20th 06 11:51 PM
Read-only access by SHEET (not workbook). Is it possible? emcphee Excel Worksheet Functions 5 February 4th 06 10:42 PM
link Access workbook to Excel workbook Toinett Excel Discussion (Misc queries) 1 January 31st 05 03:37 PM
Using ADO to access another workbook Jack Excel Programming 4 December 1st 04 09:42 PM
Can't access to a WorkBook Jordi Excel Programming 1 November 15th 03 06:24 AM


All times are GMT +1. The time now is 08:47 PM.

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

About Us

"It's about Microsoft Excel"