Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module1 vs Thisworkbook for Macro


I have written macro code where the error is "Procdure is too long". I
am manipulating a lot of mainframe data and charting it. The code ran
until I got the "too long" error.

I have stored all the code in the "ThisWorkbook" so that the code is
available to all sheets.

Should I move the code to "Module1"? "Module1" was created when I
recorded a macro to determine needed code.

Can you have multiple "Modules"?

Is it desireable to have multiple "Modules"?

Would the move eliminate the "too long" error?

Would variables be available for all the sheets in the workbook?

Really confused after a long night of pushing code.

Craigm


--
Craigm
------------------------------------------------------------------------
Craigm's Profile: http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=382754

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Module1 vs Thisworkbook for Macro



procedures should never go in an object module
unless there is a good reason.

thus: always use "normal" modules, except for
event handlers.

moveing your code to a normal module wont solve
procedure too long.

that should be solved by "hacking" your procedure
into pieces...

ideally your variables should be at procedure level.
and those variables that need to be "shared" should be passed
as arguments to the called procedure.

However for a quick fix you need now..
move all your variables to module level (before the first procedure or
function)

make 5 or 10 separate procedures from your original.
then add 1 main procedure at the top that calls the others.

dim wks as worksheet
dim rng as range

Sub mainproc()
call proc1
call proc2
call proc3
end sub

Sub proc1()
'blah
End Sub









--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Craigm wrote :


I have written macro code where the error is "Procdure is too long".
I am manipulating a lot of mainframe data and charting it. The code
ran until I got the "too long" error.

I have stored all the code in the "ThisWorkbook" so that the code is
available to all sheets.

Should I move the code to "Module1"? "Module1" was created when I
recorded a macro to determine needed code.

Can you have multiple "Modules"?

Is it desireable to have multiple "Modules"?

Would the move eliminate the "too long" error?

Would variables be available for all the sheets in the workbook?

Really confused after a long night of pushing code.

Craigm

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Module1 vs Thisworkbook for Macro

I normally keep the code in the regular module and call it from the Workbook
module if I need to use the workbook events.

Yes, you can and should use multiple modules. Yes, your variables will be
available to all sheets.

Is your code the product of recordings? If so, you can reduce the lines and
improve the efficiency of the recorded code.



--
Damon Longworth

Don't miss out on the 2005 Excel User Conference
Sept 16th and 17th
Stockyards Hotel - Ft. Worth, Texas
www.ExcelUserConference.com


"Craigm" wrote in
message ...

I have written macro code where the error is "Procdure is too long". I
am manipulating a lot of mainframe data and charting it. The code ran
until I got the "too long" error.

I have stored all the code in the "ThisWorkbook" so that the code is
available to all sheets.

Should I move the code to "Module1"? "Module1" was created when I
recorded a macro to determine needed code.

Can you have multiple "Modules"?

Is it desireable to have multiple "Modules"?

Would the move eliminate the "too long" error?

Would variables be available for all the sheets in the workbook?

Really confused after a long night of pushing code.

Craigm


--
Craigm
------------------------------------------------------------------------
Craigm's Profile:
http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=382754



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module1 vs Thisworkbook for Macro


I am learning fast with your help!

Thank you,

Craigm


--
Craigm
------------------------------------------------------------------------
Craigm's Profile: http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=382754

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module1 vs Thisworkbook for Macro


Set wbBook = Workbooks("C:\Temp\Charts_ChgAll2.xls")
-------------------------
I moved all the code from "Thisworkbook" to "Module1" in the same
workbook

Now I am getting a "Subscript out of range error" on the above line?


--------------------------------------------------------------
I am strangely confused and in the deep end too.

Craigm


--
Craigm
------------------------------------------------------------------------
Craigm's Profile: http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=382754



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
Can Macro update "ThisWorkbook" sheet? Don Excel Discussion (Misc queries) 1 February 18th 09 07:58 PM
Programatically adding macro to Excel - "ThisWorkbook" Aerojade Excel Discussion (Misc queries) 3 October 1st 08 12:53 PM
UDF error when renaming Module1 RonaldF Excel Programming 4 November 27th 04 05:21 PM
Empty ThisWorkbook module, but Macro warning problem Stuart[_5_] Excel Programming 3 June 28th 04 07:20 PM
size/space problem with module1 in VB even though it is empty mcpheat Excel Programming 1 June 10th 04 01:06 PM


All times are GMT +1. The time now is 09:35 AM.

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"