View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Pete Merenda Pete Merenda is offline
external usenet poster
 
Posts: 7
Default run macro on only one open workbook

Tom,

Thanks for your help, but unfortunately this code does not accomplish the
goal of my original question. When I open more than one Excel wkbk with this
code running on open, it runs on all open workbooks, thus running in a loop
until it runs into a stacking space error. What command is necessary for the
code to stop after running only on the workbook that has been called to open?

Thanks

"Tom Ogilvy" wrote:

Sub PasteTotalfromADs()
ThisWorkbook.Activate
With thisworkbook.Sheets("Taylor")
.Activate
.Unprotect
.Range("C49:D56").Copy
.Range("C6").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
.protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End With
End Sub

In the 'This Workbook' object:
Private Sub Workbook_Open()
PasteTotalfromADs
End Sub

--
Regards,
Tom Ogilvy


"Pete Merenda" wrote in message
...
The macro, in Module 1 is:
Sub PasteTotalfromADs()
Sheets("Taylor").Select
ActiveSheet.Unprotect
Range("C49:D56").Select
Selection.Copy
Range("C6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("C58:D65").Select
Application.CutCopyMode = False
ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

In the 'This Workbook' object:
Private Sub Workbook_Open()
PasteTotalfromADs
End Sub

Unfortunately, I don't know the code to specify that the macro run only on
the active workbook (ActiveWorkbook.Select??). Is that all I need? Do I
need an Exit Sub statement?

Thanks for your help

"Bob Phillips" wrote:

probably because it has a reference to that workbook.

Post the code.

--
HTH

Bob Phillips

"Pete Merenda" wrote in message
...
I have several workbooks, each with a macro (to rearrange data) that

runs
"on
open". When I open a second workbook (wk2), the macro runs, then
encounters
an error when it tries to run (re-run) the macro on the first workbook
(wk1).
My goal is have the macro fire only on the workbook that I'm opening,

and
then stop.

I'm curious as to why the macro on wk1 tries to run when the open

event
has
not occurred. Do I need some type of command to stop the macro in

wk2?