XL: Deactivate Macro Doesn't Run When You Open HTML Document
ID: Q180699
|
The information in this article applies to:
-
Microsoft Excel 97 for Windows
-
Microsoft Excel 98 Macintosh Edition
SYMPTOMS
When you open a workbook, a macro that is designed to run when you
deactivate the active worksheet does not run.
CAUSE
This problem occurs when the following conditions are true:
- An OnSheetDeactivate macro is assigned to the active worksheet
or workbook, or a macro is attached to the Deactivate event of
the active worksheet.
-and-
- You open a Hypertext Markup Language (HTML) document in Microsoft Excel.
When you open an HTML document, OnSheetDeactivate and Deactivate macros
that are assigned to the active worksheet do not run. However, after you
open the HTML document, the OnSheetDeactivate and Deactivate macros work
correctly.
NOTE: This problem does not occur when a macro is attached to the
Deactivate event of the active workbook.
WORKAROUND
To work around this problem, follow these steps:
- Click the worksheet that was active when you opened the .htm
document.
- Switch to the HTML document.
The OnSheetDeactivate or Deactivate macro runs correctly.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article.
MORE INFORMATION
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to
provide added functionality or construct procedures to meet your specific
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
To create an OnSheetDeactivate macro in Microsoft Excel, follow these
steps:
- On the Tools menu, point to Macro, and then click Visual Basic Editor.
- On the Insert menu, click Module.
- Type the following code into the new module:
Sub Trigger()
Sheets("Sheet1").OnSheetDeactivate = "RunMe"
End Sub
Sub RunMe()
MsgBox "You deactivated Sheet1."
End Sub
- Run the Trigger macro.
When you deactivate Sheet1, the macro specified in the OnSheetDeactivate
command ("RunMe") is run. You can specify any worksheet or workbook when
you use OnSheetDeactivate; if you specify a workbook, the macro is run when
you deactivate any sheet in the workbook.
You can also use the Deactivate event of a worksheet to run a macro. To do
this, follow these steps:
- On the Tools menu, point to Macro, and then click Visual Basic Editor.
- In the Project window, double-click the sheet for which you want to
add a macro.
- In the Object list, click Worksheet. In the Procedure list, click
Deactivate.
- Change the code in the Code window to the following:
Private Sub Worksheet_Deactivate()
MsgBox "You deactivated Sheet1."
End Sub
- On the File menu, click "Close and Return to Microsoft Excel."
When you deactivate Sheet1, the Worksheet_Deactivate macro runs
automatically. It is not necessary to use a second macro to set the
Worksheet_Deactivate macro to run.
Example
To see an example of this problem, follow these steps:
- Create a new workbook, and repeat steps 1 through 5 above.
- On the File menu, click Open. Select an HTML document, and then click
Open.
The macro does not run.
- Switch to the workbook and click Sheet1. Then, switch to the .htm
document.
The macro runs as expected.
Additional query words:
XL97 XL98 htm .htm .html
Keywords : kbdta xlloadsave KbVBA xlweb
Version : MACINTOSH:98; WINDOWS:97
Platform : MACINTOSH WINDOWS
Issue type : kbbug
|