Gass
Gass

Reputation: 9384

Create an IF statement in VBA for operating system

I want to create an IF statement to change a string depending on the operating system. Is this possible?

Idea:

Sub create_path()

Dim os_is_mac As Boolean
Dim slash As String

If os_is_mac Then
   slash = "/"
else: slash = "\"
End if

end sub

Upvotes: 0

Views: 127

Answers (1)

sbgib
sbgib

Reputation: 5838

Try like this:

Sub create_path()

    Dim os_is_mac As Boolean
    Dim slash As String
    
    os_is_mac = Application.OperatingSystem Like "*Mac*"
    
    If os_is_mac Then
        slash = "/"
    Else
        slash = "\"
    End If

End Sub

Upvotes: 1

Related Questions