Conditional compilation VBA Excel Mac/Win/32/64…

To make my addin handle all the combinations of Excel 2007 onwards on Mac and Windows, 32-bit and 64-bit, I ended up with this conditional compilation block. The example I use is GetTickCount() but the principle applies to other declarations.

Microsoft say “We expressly DO NOT support external use of Win32 APIs on the Mac, even if we have an implementation of them in the Office frameworks.” If you ever find documentation on these, let me know.

'https://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx
'Compatibility Between the 32-bit and 64-bit Versions of Office 2010
'Apple has deprecated HFS on the Mac, so Mac Office 2016 no longer uses or supports HFS paths.
'You must use POSIX paths (with "/" as the directory separator) in Mac Office 2016.
' In Macscript, when getting folders or files in Mac Office 2016,
' insert "return posix path of " before "(choose folder..."

#If Mac Then
 #If MAC_OFFICE_VERSION >= 15 Then
  #If VBA7 Then ' 64-bit Excel 2016 for Mac
   Declare PtrSafe Function GetTickCount Lib _
"/Applications/Microsoft Excel.app/Contents/Frameworks/MicrosoftOffice.framework/MicrosoftOffice" () As Long
  #Else ' 32-bit Excel 2016 for Mac
   Declare Function GetTickCount Lib _
"/Applications/Microsoft Excel.app/Contents/Frameworks/MicrosoftOffice.framework/MicrosoftOffice" () As Long
  #End If
 #Else
  #If VBA7 Then ' does not exist, but why take a chance
   Declare PtrSafe Function GetTickCount Lib _
"Applications:Microsoft Office 2011:Office:MicrosoftOffice.framework:MicrosoftOffice" () As Long
  #Else ' 32-bit Excel 2011 for Mac
   Declare Function GetTickCount Lib _
"Applications:Microsoft Office 2011:Office:MicrosoftOffice.framework:MicrosoftOffice" () As Long
  #End If
 #End If
#Else
 #If VBA7 Then ' Excel 2010 or later for Windows
  Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
 #Else ' pre Excel 2010 for Windows
  Declare Function GetTickCount Lib "kernel32" () As Long
 #End If
#End If

 

See http://www.rondebruin.nl/mac/ for lots more on Excel for Mac, in particular Macscript code for file and folder dialogs.

For Windows API declarations with the new LongPtr type, see

http://www.jkp-ads.com/articles/apideclarations.asp

My previous posts on Excel for Mac are here:

https://sysmod.wordpress.com/2011/10/21/list-of-mac-excel-2011-differences-from-excel-2011/

https://sysmod.wordpress.com/2011/10/24/more-differences-mainly-vba/

https://sysmod.wordpress.com/2011/10/28/mac-excel-vs-pc-excel/

 

 

 

 

 

 

 

Advertisements

About Patrick O'Beirne, spreadsheet auditor

Patrick provides consultancy and training in spreadsheet development, auditing / testing and model review; and the Excel addin XLtest
This entry was posted in Excel/VBA, Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Conditional compilation VBA Excel Mac/Win/32/64…

  1. Culey says:

    Is there a list of declarations by API function for Mac 2011 and 2016 anywhere? There are a few for Windows but have struggled to find one for Macintosh.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s