What is "#" doing/saying when it leads a line of code?

wornhall

Board Regular
Joined
Feb 16, 2016
Messages
67
In this code, for example, what is the effect of the "#" sign?

Public Function Exists(Key As Variant) As Boolean
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Exists = Not IsEmpty(dict_GetKeyValue(Key))
#Else
Exists = dict_pDictionary.Exists(Key)
#End If
End Function

I have searched high and low, and cannot find this information.

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
That is conditional compilation.

If it is run on a Mac it will compile and execute
Code:
Exists = Not IsEmpty(dict_GetKeyValue(Key))
and ignore (and not even try to compile)
Code:
Exists = dict_pDictionary.Exists(Key)

otherwise, the reverse.

This protects computers from trying to compile code that they don't support. For example, this protects a PC from trying to compile the MacScript code, that it doesn't support.
Code:
#If Mac Then
    FolderPath = MacScript("choose folder")
#Else
    'FolderPath = (windows code that I don't know)
#End If

A simple IF will compile the code in both branches. Or at least try, and crash if that code isn't supported by the machine running the code.

Conditional Compliation will not compile the code in the un-run branch.
 
Upvote 0
To follow up on Mike's post, if you Google this...

vba conditional compilation

you will get a bunch of links where you can find out more information about it.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top