PDA

View Full Version : Detect Conditional Compilation Setting via code



Shred Dude
04-26-2011, 01:16 PM
Does anyone know a way to check for conditional compilation settings on a closed file?

I often use a conditional compilation setting on projects to toggle between debug mode and release mode with something like:

conDEBUG=1

in the Properties of a VBA Project. This will establish a constant value in my code at run-time that then effects the behavior of error handling.

Inevitably, in my haste to send an enhancement version to someone, I'll email them a file with that setting still set to 1 (true) instead of 0. This can end up promoting undesired behavior on their end in the event the workbook hits an error.

I took a look through the object browser and didn't find a way to read those values from a project. maybe there's an API...?

And often times I'll have the project password protected too.

I'm just exploring whether I can write a routine to check .xlsm & .xlam file attachments before getting sent through Outlook for the value of the various conditional compilation settings. At a minimum I guess I could just pop up a msgbox when such a file type is attached to ask myself if I've verified the settings before sending. I'm just curious if there'd be a way to automate that.

Any ideas???

Thanks,

Shred

Paul_Hossler
04-26-2011, 02:05 PM
Easiest way I could come up with


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
#If conDEBUG = 1 Then
MsgBox "Remember, you're still in Debug Mode"
#End If


Paul

Shred Dude
04-28-2011, 03:28 PM
Paul:

Thanks for the input. That's a great idea. I was stuck thinking about it from the perspective of the file already being closed and attaching it to an email.

I've adapted the concept to report on all conditional compilation flags I typically use and rolled into my primary development template.

It would be nice if there was a way to iterate the collection of conditional compilation settings with a For/Each loop for example though so I could have a standard code snippet to create a message box reporting the status of each one. In one project I might have A,B, & C, and in another I might use B, C, & D for example.

Shred