View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Green[_2_] John Green[_2_] is offline
external usenet poster
 
Posts: 58
Default run a macro on an in-active workbook

You can refer to cells in non-active workbooks by fully qualifying the references. Something like:

x = Workbooks("A.xls").Worksheets("Sheet1").Range("A1" ).Value

If you need to make lots of references to the same object, use the following:

With Workbooks("A.xls").Worksheets("Sheet1")
x = .Range("A1").Value
.Range("A2").Value = x

End With

--

John Green - Excel MVP
Sydney
Australia


"jfeka" wrote in message ...
Is there any way to get a macro to execute on a workbook
which is open, but not active?

I have a macro in a certain workbook (call it "A")which
repeats automatically but if I I open another workbook,
say "B", then the macro produces an error because it
doesn't find the data it needs in the active worksheet if
I'm working in "B".

I've added the following code to the start of my macro

Workbooks("hilowwork book.xls").Activate
Worksheets("UpdateInfo").Activate

and the macro runs fine but it causes the sheet to become
active and it interrupts the work I may be doing in
workbook "B".

Is there some way I can feed the macro the information of
the workbook name and sheet name that it is to operate on
so that it does this in the background and still allows
me to continue working in workbook "B" without
interruption?