First Aid For Macros

C

Chuckles123

I had (fortunately, not have) a sick macro (at least I think HAD). Whe
opening, and when saving, the workbook containing the macro, I receive
"Compile error: Invalid outside procedure" -- on the same screen,
range name or a cell location in the coding would be highlighted.
Also, when doing Alt+{F8}, the name of the macro with the problem di
NOT appear; furthermore, the other 12 macros listed had the file nam
plus the Module number preceding each macro name.

My solution was to copy the macro contents to the Clipboard, delete al
of the text in the problem macro, and then save the workbook. I the
re-opened the workbook (this time there was no problem). I the
created a new macro, re-named it, pasted the text from the Clipboard
and then saved the workbook.

I have two theories as to what happened:

As I said above, 13 macros; all but one (not the problem macro) of the
are connected, maybe a 1,000 lines of code. Somehow, I have about 8
Modules; I have made numerous macro edits -- I did nothing else that
am aware of to create these Modules. Is this a problem?

Secondly, I have 3 MsgBoxes in these macros (2 of them are in th
problem macro), each containing Yes and No buttons. Each has th
following line of code: Dim Msg, Style, Title, Response. I think whe
I had created only 2 of these boxes, the compiler did not have
problem. But, when I created the third, the compiler definitely had
problem -- I deleted one or two of the Dim lines and everythin
appeared to work OK.

I also had two Dim Target as Range lines, each involving only two line
of code: Target.FormulaR1C1 = ... ; and Target.Value = Target.Value (
think both of these Dim lines are in the same macro, but not th
problem one); the compiler forced me to delete one of these Dim lines.

Are my Dim lines a problem? I would like to create one more MsgBox.

Any help would be appreciated.

Chuckles12
 
T

Tom Ogilvy

To remove a module, go to the project explorer in the VBE and right click on
a module in the project tree. Choose Remove and don't export the code if
you don't need it (I assume you would only delete modules you didn't need
and I couldn't imagine that you need 80 modules.).
Dim Target as Range lines, each involving only two lines
of code: Target.FormulaR1C1 = ... ; and Target.Value = Target.Value
These aren't Dim lines (note that dim does not appear in either.) these are
assignment statements.

Dim is to define a variable in terms of scope and type.

sub Macro1()
Dim myvar as Long '<== Dim statement
myvar = 12 '<== Assignment statement
msgbox Myvar '<== command
End sub

--
Regards,
Tom Ogilvy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top