1

Hello_ everyone I have this scenario that I have some public properties that are inside a module. In workbook's Private Sub Workbook_Open() method I do initialize those properties and assign some values to them.

After I get some error/exception those properties values are lost and I need to close and open again the workbooks so the functionality to work fine.

Had someone meet this problem and do you have any idea what is causing it and how to handle it?

Thanks_ in advance.

Community
  • 1
  • 1
codtex
  • 6,128
  • 2
  • 17
  • 34

1 Answers1

3

I take it your code stops after the error, which would cause the variables to lose scope.

Have a look at the accepted answer on this question: What is the lifetime of a global variable in excel vba?

I'd say the best way around this is to handle the error so your code keeps running - it's impossible to say exactly how without knowing the errors and seeing the code.

Or you hold the initial values in a hidden worksheet and retrieve them if needed (as @Gary's Student has just commented).

Community
  • 1
  • 1
Darren Bartrup-Cook
  • 18,362
  • 1
  • 23
  • 45
  • I understood from answer that you put link that probably An unhandled runtime error is causing the trouble, Thanks_ – codtex Dec 23 '16 at 14:30