LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default moved code to new book - some doesn't work now

That did it. Thank you.

"OssieMac" wrote:

When you place code in another workbook then you need to specify which
workbook the code is to be applied to whenever it is run. If this is not done
then the code will most likely operate on whatever workbook is the active
workbook at the time. I am surprised that you say one line of the code works
and the other does not however, I am attributing that to maybe an error when
attempting to post a simplified version of your code.

One way of achieving the above is to pass the workbook to the code as an
argument at the time it is called and pick up the workbook as a parameter in
the called sub. Then use the parameter in the code.

The calling code:
Application.Run "'Book2'!Macro1", ThisWorkbook


The called macro. (Note the parameter wb in the Sub line and the use of
wb.Worksheets("Sheet1") where the variable wb refers to the calling workbook.)

Sub Macro1(wb As Workbook)

With wb.Worksheets("Sheet1")
.Columns("A:I").ClearContents
.Cells(10, 3) = "Title1"
End With

End Sub


--
Regards,

OssieMac


"lallen" wrote:

I recently moved all the code from one workbook to another so that it could
be shared amont multiple books, by making the following change in the
worksheet_activate sub in Sheet1:

from Call Macro1
to Application.Run "'Book2'!Macro1"

Now, some of the code works, and some doesn't. For example:

With Worksheets("Sheet1")
.Columns("A:I").ClearContents ' does nothing
.Cells(10,3) = "Title1" ' works
End With

What am I doinf wrong?



 
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
VBA code to email active work book PAG Excel Programming 1 May 19th 09 09:22 PM
searching by number or code ina work book justsomeguy Excel Discussion (Misc queries) 0 February 19th 07 08:55 PM
moved vba code from macro to command button, now won't work Charles Chickering Excel Programming 0 January 12th 07 10:18 PM
Please Help!!! How Do I Specify A particualr work book to execute code on MrGreenFingas Excel Programming 3 September 1st 05 12:08 PM
Maintaining a hyperlink to moved data within the work book Kev Nurse Excel Discussion (Misc queries) 1 January 28th 05 01:22 AM


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

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

About Us

"It's about Microsoft Excel"