2012-08-03 3 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

... –

답변

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 

가 잘 작동, 오류없이 하위 Demo_OK을 실행합니다. 오류 13을 반환 작동하지와 하위 Demo_Error 실행

, 내가 당신의 질문을 이해 확실하지 오전 type mismatch

+0

HA HA HA HA, 나는 내 귀를 물린 수 있습니다! :-) 나는 게시하기 전에 내 자신의 예제를 시도하고 그것이 작동하지 않았다는 것을 맹세한다. 나는 틀린 무엇인가 타이핑하고 있었을 것임에 틀림 없었다. 크리스 고마워. – CaBieberach

관련 문제