Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Open an existing workbook and reference it

Hey all,
I have a template that needs to prompt the user to open an existing workbook
and then be able to reference that workbook's worksheets in order to copy
various columns from worksheets in the template over to the existing workbook
that was just opened.
Can anyone offer the best way to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Open an existing workbook and reference it

My preference is to use workbook, worksheet and range objects to access data
in external workbooks. Something like this...

Sub GetStuff()
Dim wbkOpened As Workbook
Dim wksExternalSheet As Worksheet
Dim rngExternalRange As Range

On Error GoTo OpenFileError
Set wbkOpened = Workbooks("This.xls")
On Error GoTo 0
Set wksExternalSheet = wbkOpened.Sheets(1)
Set rngExternalRange = wksExternalSheet.Range("A1:B10")

rngExternalRange.Copy ThisWorkbook.Sheets("Sheet1").Range("A1")

Exit Sub
OpenFileError:
Workbooks.Open "C:\This.xls"
Set wbkOpened = Workbooks("This.xls")
Resume Next
End Sub

This copies a range from a workbook called this which may or may not be open
when the code executes. it copes some stuff from the first sheet back into
Thisworkbook...
--
HTH...

Jim Thomlinson


"TimT" wrote:

Hey all,
I have a template that needs to prompt the user to open an existing workbook
and then be able to reference that workbook's worksheets in order to copy
various columns from worksheets in the template over to the existing workbook
that was just opened.
Can anyone offer the best way to do this?

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
How do I set up a workbook to open on a cell reference every time CAHM Excel Discussion (Misc queries) 2 November 30th 07 05:41 PM
existing workbook,want to create chart-wizard will not open Toby Charts and Charting in Excel 0 November 21st 06 05:24 PM
Can't open existing file LisaK Excel Discussion (Misc queries) 3 April 18th 06 10:14 PM
Blank workbook opens when try to open any existing book poloboyUK Excel Discussion (Misc queries) 2 February 2nd 06 08:35 PM
Open existing workbook Daniel Van Eygen Excel Programming 4 August 25th 04 02:47 PM


All times are GMT +1. The time now is 09:57 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"