1

是否可以在 VBA 的条件编译中使用字符串常量?

例如:

#Const This_File_Concept="Chancleta"
'
#If This_File_Concept="Chancleta" then
     ''...Something happens

#End If
'    
#If This_File_Concept="Auto" then
     ''...Something different happens

#End If
'    
#If This_File_Concept="Freesbee" then
     ''...Another thing happens

#End If

谢谢 !

4

1 回答 1

2

简短的回答:是的

示范:

#Const This_File_Concept = "Chancleta"

#If This_File_Concept = "Chancleta" Then
     Dim zx As Long
#End If
'
#If This_File_Concept = "Auto" Then
     Dim zx As String
#End If
'

Sub Demo_OK()
    #If This_File_Concept = "Chancleta" Then
         zx = 1
    #End If
    '
    #If This_File_Concept = "Auto" Then
        zx = "Hello"
    #End If
End Sub

Sub Demo_Error()
    #If This_File_Concept = "Chancleta" Then
         zx = "Hello"
    #End If
    '
    #If This_File_Concept = "Auto" Then
        zx = 1
    #End If
End Sub

运行 SubDemo_OK工作正常,没有错误。

运行 SubDemo_Error不工作,返回错误 13,type mismatch

于 2012-08-03T08:00:53.907 回答