Microsoft KB Archive/139575

From BetaArchive Wiki
Knowledge Base


Macro Recorded to Add Sheet Template Incorrect

Article ID: 139575

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Excel 95 Standard Edition



This article was previously published under Q139575

SYMPTOMS

When you record a Visual Basic for applications macro that adds a sheet template to a Microsoft Excel version 7.0 workbook, you will get a line of code similar to the following:

   Sheets.Add Type:= "C:\MSOFFICE\TEMPLATES\SHEET.XLT"
                

When you run this code, you receive the following error message:

Run-Time Error '1004' Add method of sheets class failed

CAUSE

The value for the Type argument must be a Microsoft Excel sheet constant. The sheet constants are as follows:

xlWorksheet
xlChart
xlModule
xlDialogSheet
xlExcel4MacroSheet
xlExcel4IntlMacroSheet


WORKAROUND

To work around this problem, use the following steps:

  1. Save the template as Sheet.xlt in your Excel\Xlstart folder.
  2. Restart Microsoft Excel.

Now you can record the macro to insert the template and the recorded macro.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: XL7

Keywords: kbprogramming KB139575