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を実行しても正常に動作し、エラーは発生しません。

動作しないサブルーチンを実行Demo_Errorすると、エラー 13 が返されます。type mismatch

于 2012-08-03T08:00:53.907 に答える