Writing VBA for both Windows and Macintosh

Microsoft has brought VBA back for Mac world with its latest Office. But there are many differences between two version. To write macros that run smoothly on both systems you need to began with system recognition. Follow snip-set let you do it

Function isMac() As Boolean

   If Application.OperatingSystem Like "*Mac*" Then
      isMac = True
   Else
      isMac = False
   End If

End Function

Sub myMacro ()

   if isMac() then
      'code for Mac here
   else
      'code for Win here
   end ifEnd Sub
Advertisements


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