代码之家  ›  专栏  ›  技术社区  ›  Gass

在VBA中为操作系统创建IF语句

  •  0
  • Gass  · 技术社区  · 4 年前

    我想创建一个IF语句来根据操作系统更改字符串。这可能吗?

    想法:

    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
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   sbgib    4 年前

    试试看 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