Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:51:32+00:00 2026-05-30T03:51:32+00:00

I need to temporarily store my macro’s settings for each worksheet. I thought about

  • 0

I need to temporarily store my macro’s settings for each worksheet. I thought about extending the active sheet’s properties to store the settings there. The goal would be to read a property such as ActiveSheet.Setting1. I’ve tried wrapping the ActiveSheet object in a class:

“cCustomSheet” class module:

Public WithEvents WS As Worksheet
Public Setting1 As String

“Module1” module:

Dim ActiveWS As cCustomSheet
Sub test1()
    Set ActiveWS = New cCustomSheet
    Set ActiveWS.WS = ActiveSheet
End Sub
Sub test2()
    MsgBox ActiveWS.WS.Name
End Sub

This code works without an error, but ActiveWS should be updated to the new active sheet if the user activates another sheet, and it’s not. If I remove the Set keyword from the line Set ActiveWS.WS = ActiveSheet, I get the following error:

Error n° 91: Object variable or With block variable not set

How should I do it, and is this even possible?

I also thought about using ActiveSheet.CustomProperties but this seems rather clumsy since you can’t retrieve a setting by its name (without looping through all of the items), and you have to rely on index numbers.

Thanks in advance.

Update: I should add that my macro will be stored as an Excel Add-in, therefore I won’t have access to the code of the workbooks of the users. I cannot take advantage of the Worksheet_Activate() event to keep track of the active sheet. Also, the settings would preferably be lost or reset to their default values when the workbook is reopened, that’s why I can’t save them inside the user’s file (in a hidden sheet for example).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:51:34+00:00Added an answer on May 30, 2026 at 3:51 am

    Thanks everyone for your suggestions. They have helped me finding a way to store my settings for each worksheet. I’ve used ActiveWorkbook.CustomDocumentProperties to assign a random ID to the active workbook. Each worksheet is identified by the concatenation of the workbook’s ID and the sheet’s codename (which is unique inside a workbook). The settings for the active worksheet are added to a collection where the sheet’s ID serves as the index, so that they can be retrieved easily.

    This is not 100% safe since two workbooks can hypothetically get the same ID, since it’s a random number. The workbook’s ID is also saved to the Excel file. It becomes useless after the workbook is closed but “pollutes” the custom properties list of the file.

    I also needed to store the address of the column holding the values on which to apply my macro. This is set by the user. Instead of storing the absolute address of the range, I’m using the .ID property of the first cell of the column. This way, if the user moves the cells, the ID sticks to the values. The downside is that I have to cycle through every cell of the first row of the selection to check if a cell holds an .ID value, which is quite inelegant. The .ID property is gone after the workbook is reopened, which is fine for me because I didn’t want the settings to be persistent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need something like a temporary in-memory key-value store. I know there are solutions
I need a way to store a value somewhere for temporarily by say Process
I need to store uploaded files temporarily while a user decides how they want
I'm running ASP.NET MVC and need a safe way to store credit-card data temporarily
I need to temporarily store the content of a NSManagedObject into a dictionary. Because
I need to be able to temporarily store a complete PHP object (containing some
I need to store data temporarily at the client-side to allow users to add,
I need to temporarily store the value in a PHP variable because the value
I need to collect some data and temporarily store it in memory and then
I have a string(xml) and I need to store it temporarily as memory stream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.