Excel

64ビット環境かどうかを判別するVBAマクロ

2年以上前にMicrosoft Community(当時はMicrosoft Answers)で回答したときのコードです。

・ExcelでWin7_32bitOSか64bitOSを判断
http://answers.microsoft.com/thread/951ca707-4eb1-4751-8050-a2968e3cd788

忘れないように記事として残しておくことにします。

Public Sub Sample1()
  Dim colItems As Object
  Dim itm As Object
 
  Set colItems = CreateObject("WbemScripting.SWbemLocator").ConnectServer.ExecQuery("Select * From Win32_OperatingSystem")
  For Each itm In colItems
    Debug.Print itm.OSArchitecture
    Exit For
  Next
End Sub

・結果1:

  1. Windows 7(x64) + Office 2010(x86):64 ビット
  2. Windows Server 2008 R2(x64) + Office 2010(x64):64 ビット
Public Sub Sample2()
  Debug.Print Application.OperatingSystem
End Sub

・結果2:

  1. Windows 7(x64) + Office 2010(x86):Windows (32-bit) NT 6.01
  2. Windows Server 2008 R2(x64) + Office 2010(x64):Windows (64-bit) NT 6.01
Public Sub Sample3()
  Debug.Print CreateObject("WScript.Shell").ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
End Sub

・結果3:

  1. Windows 7(x64) + Office 2010(x86):x86
  2. Windows Server 2008 R2(x64) + Office 2010(x64):AMD64
Public Sub Sample4()
  Debug.Print CreateObject("htmlfile").parentWindow.clientInformation.cpuClass
End Sub

・結果4:

  1. Windows 7(x64) + Office 2010(x86):x86
  2. Windows Server 2008 R2(x64) + Office 2010(x64):x64

上記の結果から、WOW64環境下では正しく判別できない場合があるため、OSが64ビット環境であるかどうかはSample1のようにWMIを使うのが良さそうです。

2013年10月の人気記事前のページ

特殊フォルダーのパスを取得するVBScript次のページ

関連記事

  1. Office関連

    Officeアプリケーションのバージョン情報ダイアログから情報を取得するVBScript

    自分の手間を減らすためのスクリプトシリーズ、今回はWordやExcel…

  2. Office関連

    MemsourceのバイリンガルMXLIFFファイルから情報を抽出するWordマクロ

    近年翻訳業界では「Trados」や「memoQ」といった、“翻訳支援ツ…

  3. Office関連

    Visio Onlineで図の作成・編集ができるようになりました。

    しばらくVisio Onlineを使っていなかったので気が付かなかった…

  4. Office関連

    Office文書をパスワード付きPDFに変換するVBAマクロ

    4年ほど前に書いた、下記記事のマクロがWordでも使えるか?との質問を…

  5. Office関連

    コンテンツコントロールに外部XMLのデータをマップするWordマクロ

    Word 2007で追加された機能「コンテンツコントロール」を使うと外…

  6. Excel

    【2019年6月版】SeleniumBasicでMicrosoft Edgeを操作してみました。

    2015年と2018年にSeleniumBasicを使ってMicros…

コメント

  1. この記事へのコメントはありません。

  1. 2020年 8月 17日

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP