Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default moved macros to new book now they don't work

This is my third attempt to post this problem. My apologies for any
duplication.

I moved some macros to a new workbook (Excel 2003), so they could be shared
amongst multiple workbooks. In order to run the code in the new location, I
changed the worksheet_activate sub in the originating sheet as follows:

from Call Macro1("Parm1")
to Application.Run "'_Workbook2.xls'!Macro1(""Parm1"")"

Now some of the code doesn't work. For example:

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

Any suggestions would be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default moved macros to new book now they don't work

Please ignore this post. I found the original posting.

For some reason, the Search isn't finding my recent postings, and I'm not
being notified of responses.

"lallen" wrote:

This is my third attempt to post this problem. My apologies for any
duplication.

I moved some macros to a new workbook (Excel 2003), so they could be shared
amongst multiple workbooks. In order to run the code in the new location, I
changed the worksheet_activate sub in the originating sheet as follows:

from Call Macro1("Parm1")
to Application.Run "'_Workbook2.xls'!Macro1(""Parm1"")"

Now some of the code doesn't work. For example:

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

Any suggestions would be greatly appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default moved macros to new book now they don't work

You had some responses at your original post.

I use google to search groups.

http://groups.google.com/advanced_se...blic.excel. *

Give it enough information (you as the author, maybe a keyword or date) and
you'll find it.

======
I don't remember you getting a definitive response, though.

And I'm not sure if anyone could.

But I'd add a line to your code for testing to see if you're processing the
correct worksheet.

With Worksheets("Sheet1")

msgbox .range("a1").address(external:=true)
.Columns("A:I").ClearContents ' does nothing
.Cells(10, 3) = "line 1" ' works
End With


That external:=true portion will show you the workbook name, worksheet name and
address ($a$1 here).

lallen wrote:

This is my third attempt to post this problem. My apologies for any
duplication.

I moved some macros to a new workbook (Excel 2003), so they could be shared
amongst multiple workbooks. In order to run the code in the new location, I
changed the worksheet_activate sub in the originating sheet as follows:

from Call Macro1("Parm1")
to Application.Run "'_Workbook2.xls'!Macro1(""Parm1"")"

Now some of the code doesn't work. For example:

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

Any suggestions would be greatly appreciated.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default moved macros to new book now they don't work

This can sometimes happen if you turn it off (set False) in a procedure your
code goes into break mode. It has no effect if running in break mode. So if
you are using F8 to step through your code it will appear to not be working.
Understand that in this case it's been disabled and so is normal behavior.

Some other things to know about using ScreenUpdating:
Besides hiding screen activity while code is running, that in itself makes
your code run faster because screen activity is suspended and so doesn't
require refreshing as code executes. Another setting that commonly
accompanies this is Calculation. Even though screen activity is temporarily
suspended, Excel is still calculating whenever cell values change. It's
better to turn that off until all the work your macro is doing is finished,
then turn it on and force a calculation so values update. (A definite 'plus'
when running long procedures or processing large amounts of data)

Excel always turns ScreenUpdating back on after the procedure that turned it
off ends. If this procedure was called from another procedure that also
turned it off then it may have no effect until that procedure ends or turns
it off, ..and so on up the call stack.

It's good practice to control turning it off/on as a 'wrapper' around lines
of code that you want to hide any screen activity that may occur while it's
executing. It's easy to lose track of when you have it on or off, or if Excel
turned it off when you wanted it on. It can get very confusing and makes
debugging a harder chore than necessary. Even though Excel will turn it on
when procedures end, you should get into the habit of controlling this in
your code before&after those code segments that make changes to the UI that
you want to hide until the task is done.

Example:
Here's a reusable procedure that you can call to toggle the settings if you
want to save the typing in every procedure you need this in:

Public Sub EnableFastCode(Optional SetFast As Boolean = True)
With Application
If SetFast Then
.ScreenUpdating = False
.Calculation = xlCalculationManual
Else
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.Calculate '//update changes
End If
End With
End Sub

To use it in a procedu
'some code...

'Turn off Calculation/ScreenUpdating
EnableFastCode
'do stuff you want to hide screen activity for...
'changes to cells or UI...
'open/close workbooks...
'process lots of data...
'Turn on Calculation/ScreenUpdating, & recalculate
EnableFastCode False

'finish up...

You might want to read up on the various contexts that the Calculate method
can be used so you fully understand what global effect it has, as well as how
to use it on specific worksheets or cells.

HTH
Garry
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default moved macros to new book now they don't work

Change "..or if Excel turned it off when you wanted it on.""
to read "or if Excel turned it on when you wanted it off."

Sorry about that!


  #6   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default moved macros to new book now they don't work

Sorry!!
Not sure why my post showed up in this thread. (I'm using the website UI not
my news reader)
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
moved code to new book - some doesn't work now lallen Excel Programming 4 April 28th 10 02:30 AM
moved macros to new book, now not working lallen Excel Programming 1 April 27th 10 01:44 AM
Moved file, changed path, macros don't work donbowyer Excel Programming 3 May 22nd 06 08:27 AM
Maintaining a hyperlink to moved data within the work book Kev Nurse Excel Discussion (Misc queries) 1 January 28th 05 01:22 AM
Macros - get information from Multiple sheets in a work book? matt Excel Programming 1 November 22nd 04 02:53 PM


All times are GMT +1. The time now is 02:26 AM.

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"