この記事では、Officeの複数プラットフォームでの体験を拡張するソリューションの開発に関する新しいOfficeアドインモデルについて説明しています。Officeアドインは、VSTOアドインと比較して小さなサイズを持ち、HTML5、JavaScript、CSS3、XMLなど、ほとんどのウェブプログラミング技術を使用して構築できます。また、ワークブックを開くための様々なパラメータやオプション(ファイル名、更新リンク、読み取り専用、パスワードなど)についての詳細な説明が含まれています。サポートやフィードバックについての情報も提供されています。
Excel ワークブックのオープンに関するガイド
概要
Excel では、VBA を使用してワークブックをプログラムで開くことができます。本記事では、Workbooks.Open
メソッドの構文、パラメーター、戻り値、そして具体的なコード例について詳しく解説します。
Workbooks.Open
メソッド
構文
expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru, Local, CorruptLoad)
expression
:Workbooks
オブジェクトを表す変数です。
パラメーター
名称 | 必須/オプショナル | データ型 | 説明 |
---|---|---|---|
FileName |
オプショナル | Variant | 開くワークブックのファイル名を指定します。 |
UpdateLinks |
オプショナル | Variant | 外部参照の更新方法を指定します。 |
ReadOnly |
オプショナル | Variant | ワークブックを読み取り専用モードで開くには True を指定します。 |
Format |
オプショナル | Variant | テキストファイルを開く際の区切り文字を指定します。 |
Password |
オプショナル | Variant | 保護されたワークブックを開くためのパスワードを指定します。 |
WriteResPassword |
オプショナル | Variant | 書き込み制限されたワークブックの編集用パスワードを指定します。 |
IgnoreReadOnlyRecommended |
オプショナル | Variant | 読み取り専用推奨メッセージを表示しないには True を指定します。 |
Origin |
オプショナル | Variant | テキストファイルの発生元を指定します。 |
Delimiter |
オプショナル | Variant | テキストファイルの区切り文字を指定します。 |
Editable |
オプショナル | Variant | Excel 4.0 アドインを表示ウィンドウとして開くには True を指定します。 |
Notify |
オプショナル | Variant | 読み取り/書き込みモードで開けない場合に通知リストに追加するには True を指定します。 |
Converter |
オプショナル | Variant | ファイルを開く際に最初に試すファイルコンバータのインデックスを指定します。 |
AddToMru |
オプショナル | Variant | 最近使用したファイルリストにこのワークブックを追加するには True を指定します。 |
Local |
オプショナル | Variant | Excel の言語設定に基づいてファイルを保存するには True を指定します。 |
CorruptLoad |
オプショナル | XlCorruptLoad | ファイルの読み込み方法を指定します。 |
戻り値
- 開いたワークブックを表す
Workbook
オブジェクトが返されます。
注意事項
- デフォルトでは、プログラムでファイルを開く際にマクロは有効化されます。
AutomationSecurity
プロパティを使用して、マクロのセキュリティモードを設定することができます。
コード例
以下のコードは、Analysis.xls
ワークブックを開き、その Auto_Open
マクロを実行します。
Workbooks.Open "ANALYSIS.XLS"
ActiveWorkbook.RunAutoMacros xlAutoOpen
次のコード例は、別のワークブックからシートをインポートし、現在のワークブックに新しいシートとして挿入します。
Sub ImportWorksheet()
Sheets("Sheet1").Select
PathName = Range("D3").Value
Filename = Range("D4").Value
TabName = Range("D5").Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=PathName & Filename
ActiveSheet.Name = TabName
Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1)
Windows(Filename).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
End Sub
サポートとフィードバック
Office VBA やこのドキュメントに関する質問やフィードバックがある場合は、Office VBA サポートとフィードバックをご覧ください。サポートやフィードバックを受ける方法について案内しています。
このガイドを通じて、Excel ワークブックをプログラムで開く際の基本的な理解を深めていただければ幸いです。
————-
Workbooks.Open method (Excel) | Microsoft Learn
Source link
The article discusses the process of opening workbooks in Microsoft Excel using VBA (Visual Basic for Applications). It introduces the Workbooks.Open
method, which allows developers to access and manipulate Excel workbooks programmatically. The method has various parameters that control how the workbook is opened, including:
- FileName: The name of the workbook to be opened.
- UpdateLinks: Determines how external references in the file are updated.
- ReadOnly: Opens the workbook in read-only mode if set to True.
- Password: A string for opening a password-protected workbook.
- Delimiter: Specifies the delimiter for text files.
- Editable: Indicates whether to open a file as a visible window or hidden.
- Notify: When read/write access is unavailable, this parameter can add the file to a notification list.
The article provides syntax definitions, optional parameters, and examples to illustrate how to use the method effectively. It highlights the importance of setting file access modes and handling files correctly, especially when dealing with protected or linked workbooks. Additionally, it mentions compatibility with the new Office Add-ins model, emphasizing that these add-ins can be created with web technologies.
Finally, there is an invitation for users to provide feedback or seek support regarding Office VBA, indicating a focus on community engagement and improvement.
コメント