PC Review


Reply
Thread Tools Rate Thread

How do I reference another workbook in VB?

 
 
cW
Guest
Posts: n/a
 
      24th May 2007
Hello,

Say I have this command in a sheet's VB code:

Sheets("Sheet1").Range("A1").Select

Now instead of referencing Sheet1 in the current workbook, I want to
reference Sheet1 in OtherWorkbook.xls.

How can I make this work? Any help would be greatly appreciated! =)

-Mike

 
Reply With Quote
 
 
 
 
Nick Hodge
Guest
Posts: n/a
 
      24th May 2007
Mike

You could do something like this...

Dim wbOther as workbook
Set wbOther = Workbooks.Open( "C:\YourPath\OtherWorkbook.xls")
wbOther.Sheets("Sheet1").Range("A1").Select

If it's open then just

Workbooks("OtherWorkbook").Sheets(......

Will suffice

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(E-Mail Removed)DTHIS
web: www.nickhodge.co.uk
blog (non-tech): www.nickhodge.co.uk/blog/


wrote in message
news:(E-Mail Removed)...
> Hello,
>
> Say I have this command in a sheet's VB code:
>
> Sheets("Sheet1").Range("A1").Select
>
> Now instead of referencing Sheet1 in the current workbook, I want to
> reference Sheet1 in OtherWorkbook.xls.
>
> How can I make this work? Any help would be greatly appreciated! =)
>
> -Mike
>
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      24th May 2007
Just a note about selecting a range. The sheet has to be active and the
workbook has to be active.

wbOther.Sheets("Sheet1").Range("A1").Select

could be:

wbOther.activate
wbOther.Sheets("Sheet1").select
wbOther.Sheets("Sheet1").Range("A1").Select

or
application.goto wbOther.Sheets("Sheet1").Range("A1"), scroll:=true '??



Nick Hodge wrote:
>
> Mike
>
> You could do something like this...
>
> Dim wbOther as workbook
> Set wbOther = Workbooks.Open( "C:\YourPath\OtherWorkbook.xls")
> wbOther.Sheets("Sheet1").Range("A1").Select
>
> If it's open then just
>
> Workbooks("OtherWorkbook").Sheets(......
>
> Will suffice
>
> --
> HTH
> Nick Hodge
> Microsoft MVP - Excel
> Southampton, England
> (E-Mail Removed)DTHIS
> web: www.nickhodge.co.uk
> blog (non-tech): www.nickhodge.co.uk/blog/
>
> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > Say I have this command in a sheet's VB code:
> >
> > Sheets("Sheet1").Range("A1").Select
> >
> > Now instead of referencing Sheet1 in the current workbook, I want to
> > reference Sheet1 in OtherWorkbook.xls.
> >
> > How can I make this work? Any help would be greatly appreciated! =)
> >
> > -Mike
> >


--

Dave Peterson
 
Reply With Quote
 
CW
Guest
Posts: n/a
 
      26th May 2007
Awesome, that did the trick! Thanks for the help Nick and Dave.

-Mike

 
Reply With Quote
 
Nick Hodge
Guest
Posts: n/a
 
      27th May 2007
Glad it worked Mike

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(E-Mail Removed)DTHIS
web: www.nickhodge.co.uk
blog (non-tech): www.nickhodge.co.uk/blog/

wrote in message
news:(E-Mail Removed)...
> Awesome, that did the trick! Thanks for the help Nick and Dave.
>
> -Mike
>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set a reference to a Workbook w/out opening the Workbook? ryguy7272 Microsoft Excel Programming 4 30th Jul 2010 12:07 AM
Reference workbook name to cell reference Bob Maloney Microsoft Excel Programming 2 5th Dec 2007 01:14 PM
Reference different workbook chris100 Microsoft Excel Programming 2 14th Apr 2006 08:33 PM
Reference code in another workbook from a calling workbook =?Utf-8?B?RGF0YXNvcnQ=?= Microsoft Excel Programming 1 4th Jan 2005 01:13 AM
Reference a workbook based on a cell reference douga Microsoft Excel Worksheet Functions 1 17th Feb 2004 06:21 AM


Features
 

Advertising
 

Newsgroups
 


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