On/Off switch for VBA code

Posted on 2010-01-10
Medium Priority
Last Modified: 2012-05-08
Simple question for everyone...

In C++, I used to use #define to switch code on and off as follows:

#define DUMMY

#ifdef DUMMY
some code here...

If I commented out "#define DUMMY", the compiler would ignore all the code between #ifdef and #endif.

Is there anything in VBA that I can use to switch code blocks on and off like this?

Question by:ltdanp22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 29

Accepted Solution

nffvrxqgrcfqvvc earned 2000 total points
ID: 26280220

#Const DUMMY = 1

#If DUMMY Then
  '// some code
#End If

Open in new window


Author Comment

ID: 26282974
Thanks! What does the # symbol do?
LVL 29

Expert Comment

ID: 26283037
It's a conditional compilation prefix statement used in VB which should work in VBA. #Define  in VB = Const but for conditional compilation use #Const.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question