2012-08-03 84 views
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 

谢谢!

+0

我不知道我理解你的问题... – 2012-08-03 07:52:54

回答

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 

运行Sub Demo_OK与做工精细,没有错误。

运行Sub Demo_Error与不行,返回错误13,type mismatch

+0

哈哈哈哈,我能咬我的耳朵! :-)我发誓我在发布之前尝试过我自己的例子,它没有工作。我一定是打错了。谢谢克里斯 – CaBieberach 2012-08-03 08:13:20

相关问题