OS Specific VBA Code

Does your clients report OS related issues often?

Sometimes, Yes.

The Vba macro might end up in Microsoft 32 bit or 64 bit or a Mac IOS system. How to make a Vba code compatible with different Operating systems.

Here is the 2 simple methods to determine OS version within Excel Macro.

64 bit Vs 32 bit  or Windows Vs Mac IOS

Introduction of 64 bit machines has many advantages. But still it is a headache for the many developers. Since they have to migrate their old programmed codes from 32 bit to 64 bit.

They have to add bunch of code to do this verification. If you are looking to convert your already delivered 32-bit version of VBA to 64 bit version, then refer this article.

How To find OS Version using VBA?

Well, there are 2 methods.

  1. Application.Operating system is the widely used function that you will get in most of the websites. But there is another method too.
  2. Using Vba pre-processor directives. Lets see what is it all about.
Sub Find_Operating_System()
    'Get Operating System Name using Application Object
    MsgBox Application.OperatingSystem
    'OS Details using Pre-Processor Directive
    #If Mac Then
        MsgBox "Mac IOS Computer"
        #If Win64 Then
           'Microsoft Office - 64 bit version
           MsgBox "Windows 64 bit Operating system"
           'Microsoft Office - 32 bit version
           MsgBox "Windows 32 bit Operating system"
        #End If
    #End If
End Sub

Yes. VBA has inbuilt pre-processor directives to categorize operating ssytem. This method is also used to find if the code is executed in Mac or Windows.

When you refer the other article to convert 32-bit to 64 bit, this same directives are used to categorize the declaration of public variables.

This issue come mainly when you use any windows API function within your code.

Leave a Reply