Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

Excel VBA: Enabling Macro Settings

I wrote a macro method to auto-size the columns in an Excel sheet upon opening the sheet. However, this solution does not work in the case that the user has not enabled macros in Excel.

Is there any way to check if the user has VBA macros disabled in Excel, and then enable the macros with Excel VBA code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The standard way of doing this is to force the user to enable macros by use of a splash screen.

  • All the sheets in the workbook except for a spash screen are made very hidden (which can only be changed via VBA or the VBA editor)
  • if macros are enabled:
    1) When the workbook opens, the code unhides all these very hidden sheets
    2) When the workbook closes then all these sheets are made very hidden again
  • If macros are not enabled then the user can only see the Splash Screen saying "Please enable macros, close and then re-open this file"

Two links with full code for this technique are listed below

  1. Brad Yundt covers this here at TekTips
  2. Jonske at VBAeXpress

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...