XL97: Warning Appears When You Use GetObject to Open Workbook (165436)
The information in this article applies to:
- Microsoft Excel 97 for Windows
This article was previously published under Q165436 SYMPTOMS
If you run a Microsoft Visual Basic for Applications macro that uses the
GetObject method to open a Microsoft Excel workbook, you may receive the
following error message:
The workbook you are opening contains macros. Some macros may contain
harmful viruses. If you are sure this workbook is from a trusted
source, click Yes. If you are not sure and want to prevent any macros
from running, click No.
The macro pauses until you click Yes, No, or Cancel. Note that if the macro
is designed to run unattended, this behavior may cause a problem.
CAUSE
You may receive this error message when the following conditions are true:
WORKAROUND
To prevent this problem from occurring, use either of the following
methods.
Method One: Turn Off Macro Virus Protection
If you clear the Macro Virus Protection check box in Microsoft Excel 97,
the problem described in this article does not occur. However, making Macro
Virus Protection unavailable makes it possible (although unlikely) for a
macro virus to infect your Microsoft Excel workbooks.
To make Macro Virus Protection unavailable in Microsoft Excel 97, follow
these steps:
- On the Tools menu, click Options.
- Click the General tab.
- Click to clear the Macro Virus Protection check box.
- Click OK.
Note that you cannot programmatically disable the Macro Virus Protection
feature. Also, you cannot programmatically detect whether the feature is
available or unavailable; you must do this manually.
Method Two: Use SendKeys to Bypass the Error Message
If you know that the Macro Virus Protection feature is available when
you open a Microsoft Excel workbook, you can use the SendKeys method to
bypass the error message dialog box. Although this method allows you to
use the Macro Virus Protection feature, it may cause an errant "y"
character to appear somewhere in one of your programs or open files, so
use this method with caution.
To use this method, insert the following line of code into your Visual
Basic for Applications macro
SendKeys "y"
immediately BEFORE the following line of code that opens the Microsoft
Excel workbook. The following sample line of code opens the Text.xls
workbook in the My Documents folder:
Set xlWkbk = GetObject("C:\My Documents\Test.xls")
The "y" character that is sent by the SendKeys statement is used to trigger
the "Yes" button in the error message dialog box so the macro continues
running without pausing. If the dialog box does not appear, the "y" may
appear in a program or be inserted in an open file. It is not possible to
predict where the "y" will be inserted.
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbdtacode kberrmsg kbprb kbProgramming KB165436 |
---|
|