Access Violation while retrieving sheet name

0

I'm using VBA to access sheet names, nothing fancy. Every once in a while one of my workbooks will crash. Event viewer shows a access violation.

Faulting application name: EXCEL.EXE, version: 15.0.5111.1000, time stamp: 0x5c4217dd Faulting module name: VBE7.DLL, version: 7.1.10.68, time stamp: 0x58def2a6 Exception code: 0xc0000005 Fault offset: 0x001ae963

The sheets exists and I can view them in the workbook. but trying to select the sheet with vba will cause excel to crash.

Ex:

sheets(1).select  
sheets(1).name 

Does anyone have insight on how to prevent this crash from occurring?

excel
vba
asked on Stack Overflow Mar 18, 2019 by ExcelThings • edited Mar 18, 2019 by Dominique

1 Answer

0

You need to disable Compile on Demand


In the VBE Editor in Excel, click on Tools > Options > General tab and click to uncheck “Compile on Demand”.


Alternatively you can set the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0\Common

Type: DWORD

Name: CompileOnDemand

Value: 0


Altering the registry is not recommended for users who do not understand how to use it. Use at your own risk

answered on Stack Overflow Mar 18, 2019 by P0w3rshell

User contributions licensed under CC BY-SA 3.0