Translation result of vba_setup.html

Condition:

保存したファイルを開く際、セキュリティの問題から開けない場合があります。
Windowsの場合、ファイルのプロパティダイアログを表示し、下部にセキュリティの警告が出ている場合、
「許可する」にチェックを入れてから開いてください
Original
Translated
Corrected
ExcelでVBAを使う準備 - D2MatE Preparing to Use VBA in Excel - D2MatE
hljs.highlightAll(); hljs.highlightAll();
insertErrorHandlers('errorMessages', '/D2MatE/Programming/vbas_syntax.html'); insertErrorHandlers('errorMessages', '/D2MatE/Programming/vbas_syntax.html');
injectCopyBoxCSS(); initModal(); injectCopyBoxCSS(); initModal();
トップページに戻る Return to Top Page
注: Note:
VBA (マクロ) が入ったファイルは、拡張子 .xlsm で保存する必要があります。 Files containing VBA (macros) must be saved with the .xlsm extension.
アドインは .xlam で保存します。 Save the add-in as .xlam.
ExcelでVBAを使う準備 Preparing for VBA in Excel
「開発」タブを表示する Display the "Developer" Tab
Excelを開き、任意のブックを新規作成するか、既存のブックを開く。 Open Excel, create a new workbook or open an existing one.
リボンの「ファイル」タブ => 「オプション」メニューを選択します。 Ribbon's "File" Tab => Select "Options" Menu.
「Excelの基本オプション」ダイアログボックスが表示されたら、「リボンのユーザー設定」をクリック。 When the "Excel Options" dialog box appears, click "Customize Ribbon."
右側の「リボンのユーザー設定」欄で、「開発」チェックボックスをオンにする。 In the "Customize Ribbon" section on the right, check the "Developer" box.
「OK」ボタンをクリックしてダイアログボックスを閉じる。 Click the "OK" button to close the dialog box.
「開発」タブがリボンに表示されていることを確認。 Ensure the "Developer" tab is displayed on the ribbon.
VBAエディターでコードを作成する Creating Code in the VBA Editor
「開発」タブ => 「Visual Basic」ボタンをクリック。 "Developer" tab => Click "Visual Basic" button.
VBAエディターが開くので、「挿入」メニューから「モジュール」を選択。 The VBA editor opens, select "Module" from the "Insert" menu.
新しく作成したモジュールに以下のコードを入力。 Enter the following code into the newly created module.
Sub HelloWorld() Sub HelloWorld()
  MsgBox "Hello, World!" MsgBox "Hello, World!"
End Sub End Sub
VBAエディターを閉じ、Excelに戻る。 Close the VBA Editor and return to Excel.
「開発」タブ => 「マクロ」をクリック (あるいはAlt + F8) し、「マクロ」ダイアログボックスを開く。 Click the "Macros" under the "Developer" tab (or press Alt + F8) to open the "Macro" dialog box.
「HelloWorld」を選択して「実行」ボタンをクリックして実行 Select "HelloWorld" and click the "Run" button to execute
Excelにボタンを追加してVBAを実行する Add a Button in Excel to Run VBA
注: 設定でマクロを有効にする必要があります。セキュリティリスクがありますので、注意してください Note: Macros need to be enabled in the settings. Please be aware of the security risks.
「ファイル」 => 「オプション」 を開く Open "File" => "Options"
「セキュリティセンター」 => 「セキュリティセンターの設定」 をクリック  "Security Center" => Click "Security Center Settings"
「マクロの設定」  Macro Settings
「すべてのマクロを有効にする」 に変更  Change to "Enable All Macros"
「VBAプロジェクト オブジェクト モデルへのアクセスを信頼する」にチェック Check "Trust access to the VBA project object model"
 Excelを再起動 Restart Excel
フォームコントロールのボタンを追加 Add Form Control Button
「開発」タブ =>  「デザインモード」 を押して、デザインモードに入る "Development" Tab => "Design Mode" Press to enter Design Mode
「挿入」ボタン をクリック Click the "Insert" button
「フォームコントロール」 => 「ボタン」を選択し、 "Select 'Button' under 'Form Control'"
シート上でドラッグしてボタンを配置 Place Buttons by Dragging on the Sheet
「マクロの登録」ダイアログが表示されるので、 新規作成 (あるいは既存マクロを選択) The "Record Macro" dialog box appears, Create New (or select existing macro)
VBAコードを入力 Enter VBA Code
VBAエディタが開くので、以下のコードを入力 The VBA editor will open, so enter the following code
Sub RunMacro() Sub RunMacro()
MsgBox "ボタンがクリックされました!" MsgBox "Button clicked!"
End Sub End Sub
保存ボタンあるいはCtrl+Sで保存 Save using the Save button or Ctrl+S
VBAエディタを閉じる Close the VBA Editor
OKボタンを押してダイアログを閉じる Close the dialog by pressing the OK button
デザインモードボタンを押し、デザインモードを抜ける Press the Design Mode button to exit Design Mode
実行 Execution
ボタンをクリック Click the button
登録マクロの変更 Changes to Registration Macro
ボタン上でマウスの右ボタンをクリック Right-click on the button
「マクロの登録」を選択 Select "Record Macro"
外部ファイルのVBAを使う方法 How to Use External File VBA
以下のような方法で実現できます。 Can be achieved using the following methods.
(i) 外部ファイルをインポート (i) Import External Files
注: 「信頼できる VBA プロジェクト オブジェクト モデルへのアクセスを許可する」 を有効にすること Note: Enable "Trust access to the VBA project object model"
Sub ImportModule() Sub ImportModule()
  Dim vbProj As Object Dim vbProj As Object
  Set vbProj = ThisWorkbook.VBProject Set vbProj = ThisWorkbook.VBProject
  vbProj.VBComponents.Import "\path\to\module.bas"  vbProj.VBComponents.Import "\path\to\module.bas"
End Sub End Sub
(ii) 外部ファイルのVBAを実行 (ii) Execute External File VBA
Sub RunMacroFromAnotherWorkbook() Sub RunMacroFromAnotherWorkbook()
  Dim wb As Workbook Dim wb As Workbook
  Set wb = Workbooks.Open("\path\to\otherWorkbook.xlsm") Set wb = Workbooks.Open("\path\to\otherWorkbook.xlsm")
  Application.Run "otherWorkbook.xlsm!MacroName" Application.Run "otherWorkbook.xlsm!MacroName"
  wb.Close False ' 保存せずに閉じる Close without saving
End Sub End Sub
(iii) アドインを使う (iii) Use Add-ins
他のファイルを アドイン(.xlam) にして保存する Save Other Files as Add-in (.xlam)
Excelで アドインを有効化 する Enable Add-ins in Excel
Application.Run "AddInName.xlam!MacroName" でマクロを実行 Run the macro with Application.Run "AddInName.xlam!MacroName"
(iv) ライブラリ化 (参照設定) (iv) Library Configuration (Reference Settings)
VBAエディタ(VBE) で 「ツール」 → 「参照設定」 を開く Open "Tools" → "References" in the VBA Editor (VBE)
他のExcelファイルを ライブラリとして追加 する。 Add Other Excel Files as Library
含まれているVBA関数を直接呼び出せる。 Can directly call included VBA functions.
Sub RunVBAFromLibrary() Sub RunVBAFromLibrary()
  Dim obj As New MyLibrary.Module1  Dim obj As New MyLibrary.Module1
  Call obj.MySub Call obj.MySub
End Sub End Sub
(v) 外部スクリプト (VBS) を実行する (2024年に廃止されたので非推奨) (v) Execute External Scripts (VBS) (Deprecated as of 2024)
以下を、test.vbsに保存する Save the following to test.vbs
Dim objExcel, objWorkbook  Dim objExcel, objWorkbook
Set objExcel = CreateObject("Excel.Application")  Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\path\to\otherWorkbook.xlsm") Set objWorkbook = objExcel.Workbooks.Open("C:\path\to\otherWorkbook.xlsm")
objExcel.Application.Run "otherWorkbook.xlsm!MacroName"  objExcel.Application.Run "otherWorkbook.xlsm!MacroName"
objWorkbook.Close False  objWorkbook.Close False
objExcel.Quit objExcel.Quit
実行する Execute
(vi) PowerShellで実行する (vi) Execute with PowerShell
以下をtest.ps1として保存 Save the following as test.ps1
$excel = New-Object -ComObject Excel.Application $excel = New-Object -ComObject Excel.Application
$excel.Visible = $false # Excelを非表示 $excel.Visible = $false # Hide Excel
$workbook = $excel.Workbooks.Open("C:\Users\YourName\Documents\test.xlsm") $workbook = $excel.Workbooks.Open("C:\Users\YourName\Documents\test.xlsm")
$workbook.Close($false) # 保存せずに閉じる $workbook.Close($false) # Close without saving
$excel.Quit() $excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
実行 Execution
> powershell -ExecutionPolicy Bypass -File "test.ps1" > powershell -ExecutionPolicy Bypass -File "test.ps1"