Excel 非表示モジュール内でコンパイル エラーが発生しました






トップページへ

※全てのExcelで動作する保証はありません。また、内容に関し管理人は全ての責任を負いかねます(英文も併記しています)

Excelメニューへ戻る

旧タイトル

マクロを含む古いエクセルファイルをExcel2019でエラーに

 

対象

マクロを含むエクセルファイル(Excel文書、エクセルブック)で、かつ、古い形式の互換ファイル。

拡張子が xls のものが対象で、xls以外のファイルは検証していません。

この記事では以下「マクロ有りの互換ファイル(xls)」と呼びます。

 

症状

「マクロ有りの互換ファイル(xls)」をExcel2019(Office2019)で開いたら、エラーが発生しマクロが動作しなかった。

 

 

症状は全てのファイルか?

私は「マクロ有りの互換ファイル(xls)」が複数所有していますが、症状が出たの1つだけでした。ですので、「マクロ有りの互換ファイル(xls)だと必ずエラーが出る」というわけではありません。

 

 

エラーの内容(画像)

「Microsoft Visual Basic for Applications 非表示モジュール内でコンパイルエラーが発生しました。通常このエラーは、コードがこのアプリケーションのバージョン、プラットフ」
非表示モジュール内でコンパイル エラーが発生しました

「Microsoft Visual Basic for Applications 非表示モジュール内でコンパイル エラーが発生しました。通常このエラーは、コードがこのアプリケーションのバージョン、プラットフ」

 

 

特定のコード、関数か?

現時点では「特定のコードではない」と判断しています。その理由は、問題のモジュールでエラーが出て中断しても、毎回、中断する場所が異なるからです。

 

 

考えられる原因

ネット上の情報から、Excel2019からマイクロソフト社は 64bit にしたため。Excel2016以前は基本的に 32bit だったので、コードの一部で非互換が発生している模様。(意図的に64bit版Excelを入れた場合は除く)

補足ですが「私のマクロ有りの互換ファイル(.xls)」が古すぎるので、非互換のエラーが出ても仕方がないと判断しています。(現在は「Excelマクロ有効ブック(*.xlsm)」が一般的です。)

 

 

回避策

検証の前にファイルをバックアップしてから、この回避策を試されることを強くお勧めします。

手順

1. 「マクロ有りの互換ファイル(xls)」を Excel2010/2013/2016 のいずれかで開く

2. 「コンテンツの有効化」をクリック

3. 上書き保存する

4. 問題のファイルをExcel2019のパソコンにコピーして開く

5. 以上の結果、エラーが出ず、正常にマクロが動作しました。

 

その回避策のメリットは?

・コードを変更する必要がない点です。

・「マクロ有りの互換ファイル(xls)」が、Excel2016までは問題なく開いていたのにExcel2019でエラーで開かないとお困りの場合、とりあえずファイルを開くことができる点です。

 

[PR] Amazon.co.jpで ExcelのVBA の本を探す

疑問

Q. 回避策を実施すると、なぜエラーが出ないのか?

A. 不明です。

 

他にわかっていること

・「マクロ有りの互換ファイル(xls)」を、マクロ有効ブック(xlsm)として別名保存しても同じようにエラーになる。これはExcelのどのバージョンでも同じ。

 

・Excel2007で「マクロ有りの互換ファイル(xls)」を開いて保存したものを、Excel2019で開くとエラーになる。

・「マクロ有りの互換ファイル(xls)」を何もせずに、そのままExcel2019で開くとエラーになる。

したがって、2019ではない他のExcel(2010/2013/2016)で一度保存する必要がある、と判断しました。

 


Compilation error in hidden module

* There is no guarantee that it will work with all Excel. In addition, the administrator does not take any responsibility for the content.

 

subject

Excel files (Excel documents, Excel workbooks) that contain macros and are old-format compatible files.

The extension is xls, and files other than xls are not verified.

In this article, it is called “compatible file with macros (xls)”.

 

symptoms

When I opened a “compatible file with macros (xls)” in Excel 2019 (Office 2019), an error occurred and the macros did not work.

 

Are the symptoms all files?

I have multiple “compatible files with macros (xls)”, but only one symptom appeared. Therefore, it does not mean that “compatible file (xls) with macros always causes an error”.

 

Content of the error(Image)

「Microsoft Visual Basic for Applications 非表示モジュール内でコンパイルエラーが発生しました。通常このエラーは、コードがこのアプリケーションのバージョン、プラットフ」
非表示モジュール内でコンパイル エラーが発生しました

Possible cause

According to internet information, Microsoft changed from Excel 2019 to 64bit.Since Excel 2016 and earlier were basically 32bit, there seems to be some incompatibilities in the code.(Unless you intentionally installed a 64-bit version of Excel)

As a postscript, “My substitute file with macros (.xls)” is too old, so I’ve decided that it can’t be helped if an incompatibility error appears.(Currently, “Excel macro-enabled workbook (*.xlsm)” is common.)

 

 

Workaround

Before trying this workaround, we strongly recommend backing up your files before testing.

procedure

1. Open “compatible file with macro (xls)” in Excel 2010/2013/2016.

2. Click “Enable Content”.

3. Overwrite save.

4. Copy the file in question to your PC in Excel 2019 and open it.

5. As a result of the above, the macro ran successfully without any errors.

 

 

What are the benefits of that workaround?

・No need to change the code.

・If Excel 2019 could not open “compatible file with macro (xls)” due to an error even though it was opened without problems up to Excel 2016, you can open the file for now.

 

question

Q.Why does the error not occur after implementing the workaround?

A. I don’t know.

 

What else do we know

・The same error occurs even if you save “macro-enabled file (xls)” as a macro-enabled workbook (xlsm) with a different name. This is the same for any version of Excel.

・I get an error when opening and saving a “compatible file with macros (xls)” in Excel 2007 and opening it in Excel 2019.

・If you open “compatible file with macro (xls)” as it is in Excel 2019, an error will occur.

Therefore, I decided that it is necessary to save once in another Excel (2010/2013/2016) that is not 2019.

 

Excelメニューに戻る






関連記事
ExcelのVBAでエラーになった事例集

Excelメニュー

[Excel][操作]一気に先頭行、先頭列に戻る

[Excel][VBA]型変換

[Excel]2ページではなく1ページで印刷したい