0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[VBA]条件付き編纂(条件付きコンパイラ) Const Directiveでイミディエイトに環境を表示する

Posted at

条件付き編纂(条件付きコンパイラ)については以前まとめていました

今回は環境を表示させるというありそうでないものをつくりました

Show Your PC Developing Environment In VBE- Immediate Window.

コードの流れ

  1. Macintosh Windowsをわけ
  2. WindowsをVBA7互換環境かVBA6互換環境か16Bit開発環境の三通りにわけて
      1. VVBA7互換環境は64か32に
      2. VBA6互換環境は64か32か16に
  3. さらに16BitはVBA7かVBA6かによらずWin64かWin32かWin16にわける
  4. 以上の結果をイミディエイトに表示する

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がないので動作確認していません。

コード

ShowEnvironmentInImmidiate
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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?