Excel/VBA Issues


Hey Gulshan,

I am currently working on a set of reports that are generated from a web portal environment.  When the user generates the report, the data is inserted into an Excel Template and they are prompted to either Open, Save, or Cancel.

Each template has VBA code in it that runs on Workbook Open.  

We just got feedback today, that the templates are throwing a VBA code error when they select open or save and try to open it later.  I have a feeling this has to do with the "Enable Content" option that comes up each time you run the report.  They informed me that the code works fine once you enable the content, close the excel workbook and than reopen it.  

From a training point of view this would be a nightmare to educate the 1,000 plus users we have.  So I need a way to be able to run the code after the user enables the content without getting the error.

Any help you could provide is great (currenly an xlsm file - code below).

Best Regards,

Ryan Ritchie

Private Sub Workbook_Open()
   With Sheets("Certificates Due").PivotTables("PivotTable1").PivotFields("Currently Due")
       On Error Resume Next
       .PivotItems("N").Visible = False
       On Error GoTo 0
   End With
   With Sheets("In-Process").PivotTables("PivotTable5").PivotFields("Internal Status")
       On Error Resume Next
       .PivotItems("Complete").Visible = False
       .PivotItems("Frequency Changed").Visible = False
       .PivotItems("Pending Submission").Visible = False
       .PivotItems("Term Pending").Visible = False
       .PivotItems("Waived").Visible = False
       .PivotItems("Terminated").Visible = False
       On Error GoTo 0
   End With

Hey Ryan,

You might be right. It is a security feature of excel to warn users and allow them to choose whether to enable macros or not. (as a lay man, you wouldn't want to open an excel file you received by mail without knowing what macros run in it.)

However, you can set the security level as low in your system. This can be done by going to Tools - Options - Security - Macro Security (path may differ if you use excel 2007). Once you have set the macro security to low, your macros should run smoothly on file open.

Please be aware that the setting the macro security at low can also expose you to risk of viruses coming through excel macros.

Hope this helps.

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts




I can answer questions related to the following topics: 1. MS Excel - Creating and Linking Formulae, Running Pivot Tables, Vlookup etc. 2. Macros / VBA - Creating Macros to do specific jobs. Importing / Exporting / Validating Data in excel through Macros.


I've been working on excel for over 10 years and on VBA macros for over 3 years now.

Bachelor of Commerce, Chartered Accountant from The Institute of Chartered Accountants of India

©2017 About.com. All rights reserved.

[an error occurred while processing this directive]