条件付き編纂(条件付きコンパイラ)については以前まとめていました
今回は環境を表示させるというありそうでないものをつくりました
Show Your PC Developing Environment In VBE- Immediate Window.
コードの流れ
- Macintosh Windowsをわけ
- WindowsをVBA7互換環境かVBA6互換環境か16Bit開発環境の三通りにわけて
1. VVBA7互換環境は64か32に
2. VBA6互換環境は64か32か16に - さらに16BitはVBA7かVBA6かによらずWin64かWin32かWin16にわける
- 以上の結果をイミディエイトに表示する
Macが動くかは保証できず
I do not have Macintosh, so I can not recognaize if Debug.Print Statement runs Macintosh.
http://gadgets-geek.blog.jp/archives/1045571708.html
(16) イミディエイトウィンドウは既に利用可能!
(現状、ローカルウィンドウ・ウォッチウィンドウは利用不可)
などとあり、Debug.Printが効くのか自信が持てません。しかしなにもしないわけにはいかないのでDebug.Printを入れました。しかしMacintoshがないので動作確認していません。
コード
Sub ShowEnvironmentInImmidiate()
'https://docs.microsoft.com/ja-jp/office/vba/language/concepts/getting-started/compiler-constants
' If My Code does not run well, Plese Try this Official Code
# If Win64 Then
Debug.Print "Official Code : Win64=true, Win32=true, Win16= false"
# ElseIf Win32 Then
Debug.Print "Official Code : Win32=true, Win16=false"
# Else
Debug.Print "Official Code :Win16=true"
# End If
# If Mac Then
Debug.Print "Mac"
# Else
'Windows
#If VBA7 Then
#If Win64 Then
Debug.Print "VBA7 and Win 64"
#Else
Debug.Print "VBA7 and Win 32"
#End If
#ElseIf VBA6 Then
#If Win64 Then
Debug.Print "VBA6 Compatible and Win 64"
#ElseIf Win32 Then
Debug.Print "VBA6 Compatible and Win 32"
#ElseIf Win16 Then
Debug.Print "VBA6 Compatible and Win 16"
#End If
#Else
#If Win64 Then
Debug.Print "16bit Environment and Win64 True"
#ElseIf Win32 Then
Debug.Print "16bit Environment and Win32 True"
#ElseIf Win16 Then
Debug.Print "In 16 bit developping environment."
#End If
#End If
# End If
End Sub
公式の参考
https://docs.microsoft.com/ja-jp/office/vba/language/concepts/getting-started/compiler-constants
https://docs.microsoft.com/ja-jp/office/vba/language/concepts/getting-started/understanding-conditional-compilation