What does Compile VBAProject do

C

CB

Hello,
I notice in Excel VBA under the Menu "Debug" you see Compile VBAProject.
What does this do?
Kind Regards,
Charlie.B
 
J

Jim Cone

Compiling converts the code written in the VBE into code that can be read by Windows.
If you don't do it then it is automatically done when the code is run.
If the code won't compile then it won't run.
--
Jim Cone
Portland, Oregon USA
( http://tinyurl.com/PrimitiveSoftware )




"CB" <[email protected]>
wrote in message Hello,
I notice in Excel VBA under the Menu "Debug" you see Compile VBAProject.
What does this do?
Kind Regards,
Charlie.B
 
J

Jim Thomlinson

In the grander scheme of things not much from an execution stand point. Where
it is useful is that it checks your code to confirm that there are no syntax
errors. Code that has systax errors will execute up to the procedure with the
error and then it will crash. To that end it is worth compiling. Here is an
explanation of compiling in VBA...

http://orlando.mvps.org/VBADecompilerMore.asp?IdC=OrlMoreWin
 
J

JLGWhiz

That is the most coprehensive explanation that I have seen on how VBA works.
Thanks Jim.
 
C

Chip Pearson

I notice in Excel VBA under the Menu "Debug" you see Compile VBAProject.
What does this do?

VBA code is never stored as the plain text that you type in to the
editor. Input is immediately converted to platform- and
version-independent byte codes called OpCodes. These OpCodes are
converted by the editor to the text you see on the screen. When you
compile the project, the compiler translates these OpCodes to
platform- and version-specific codes called ExCodes. When you run the
code, the runtime reads the ExCodes and executes actual machine code
on behalf of the project based on the ExCodes. This whole process is
similar in principle to how Java and the Java Virtual Machine work.

If you were to export all your VBA code to text files and then remove
all the modules and then re-import the code from the text files back
into VBA (which is exactly what Rob Bovey's Code Cleaner does), you'll
see a decrease in file size. This is because the ExCodes were purged
and have not yet been recreated. Then, if you compile the project, the
file size will increase because now it stores the ExCodes in addition
to the OpCodes.

You really never need to compile the code. VBA will automatically do
it when necessary. However, the Compile command also does syntax
checking, which is its only real practical purpose.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 

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