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

  • SEARCH
  • Home
  • 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 6554705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:43:53+00:00 2026-05-25T12:43:53+00:00

I have a problem with a VBA Add-in in Excel 2010. I’ve created some

  • 0

I have a problem with a VBA Add-in in Excel 2010.

I’ve created some code for parsing my excel data. which I made into an Add-in.

However, when I load the Add-in and run, an error occurs.

The error message says: runtime error 91 object variable or With block variable not set

The error points to rowSize = ActiveSheet.Rows.Count.

Does anyone know how to fix this error?

Here is the code,

Private Sub Workbook_Open()

Dim counter As Long
Dim rowSize As Long
Dim userId As String
Dim answers As String
Dim vals As String

Dim i As Integer

rowSize = ActiveSheet.Rows.Count
counter = 1



'Create Column

ActiveSheet.Cells(1, 7).Value = "Country"
ActiveSheet.Cells(1, 8).Value = "State"
ActiveSheet.Cells(1, 9).Value = "Age"

ActiveSheet.Cells(1, 7).Font.Bold = True
ActiveSheet.Cells(1, 8).Font.Bold = True
ActiveSheet.Cells(1, 9).Font.Bold = True

ActiveSheet.Cells(1, 7).HorizontalAlignment = xlCenter
ActiveSheet.Cells(1, 8).HorizontalAlignment = xlCenter
ActiveSheet.Cells(1, 9).HorizontalAlignment = xlCenter

ActiveSheet.Cells(1, 7).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(1, 8).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(1, 9).Borders().LineStyle = xlContinuous

'Set Value
Do While counter < rowSize

If ActiveSheet.Cells(counter, 1).Value = Null Then Exit Do
If ActiveSheet.Cells(counter, 4).Value = "3" Then

    userId = ActiveSheet.Cells(counter, 2).Value
    vals = ActiveSheet.Cells(counter, 6).Value
    'MsgBox (vals)

    temp = Split(vals, ",")
    i = 0

    Do While i < 10
        targetCell = counter + i
        If ActiveSheet.Cells(targetCell, 2).Value = userId Then
           ActiveSheet.Cells(targetCell, 7).Value = temp(0)
           ActiveSheet.Cells(targetCell, 8).Value = temp(1)
           ActiveSheet.Cells(targetCell, 9).Value = temp(2)

           ActiveSheet.Cells(targetCell, 7).HorizontalAlignment = xlCenter
           ActiveSheet.Cells(targetCell, 8).HorizontalAlignment = xlCenter
           ActiveSheet.Cells(targetCell, 9).HorizontalAlignment = xlCenter

           ActiveSheet.Cells(targetCell, 7).Borders().LineStyle = xlContinuous
           ActiveSheet.Cells(targetCell, 8).Borders().LineStyle = xlContinuous
           ActiveSheet.Cells(targetCell, 9).Borders().LineStyle = xlContinuous
        End If
        i = i + 1
    Loop
    temp = Null
   'parsing_question_1(vals, userId)
End If

counter = counter + 1
Loop
End Sub

Thank you!

  • 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-25T12:43:54+00:00Added an answer on May 25, 2026 at 12:43 pm

    An add-in is just code – no user interface. Since there’s no user interface, there’s technically no sheet in the addin file that’s the ActiveSheet. There are actually sheets in an add-in, but none of them can be “active”.

    If you want to work with worksheet within the add-in, you need to reference those sheets in a different way. For instance, if you want to work with the first sheet in your add-in, you can use code like

    Me.Sheets(1).Rows.Count
    

    The Me keyword refers to the class you’re in. In this case, you’re in the ThisWorkbook module of the add-in, so Me refers the Workbook object that is the add-in.

    If you want to work on a particular sheet that’s not in your add-in, you can open that workbook in your open event and refer to that sheet. Such as

    Dim sh As Worksheet
    
    Set sh = Workbooks.Open("C:\MyPath\MyBook.xls").Sheets(1)
    
    rowSize = sh.Rows.Count
    

    Finally, if you want to run code whenever any workbook opens, you have to create a custom class module that listens for application level events. First create a custom class module call CAppEvents. In that custom class module, put this code

    Private WithEvents mApp As Application
    
    Public Property Set App(oApp As Application)
        Set mApp = oApp
    End Property
    
    Public Property Get App() As Application
        Set App = mApp
    End Property
    
    Private Sub mApp_WorkbookOpen(ByVal wb As Workbook)
        FormatWorkbook wb
    End Sub
    
    'or to limit which workbook it runs on - in this example based on the path
    'but you may use some other condition like the existence of a particular
    'custom document property
    Private Sub mApp_WorkbookOpen(ByVal wb As Workbook)
        If wb.Path = "\\Server1\mypath" Then
            FormatWorkbook wb
        End If
    End Sub
    

    In a standard module, put this code

    Public clsAppEvents As CAppEvents
    
    Sub Auto_Open()
    
        Set clsAppEvents = New CAppEvents
        Set clsAppEvents.App = Application
    
    End Sub
    
    Sub FormatWorkbook(wb As Workbook)
    
        Dim sh As Worksheet
    
        Set sh = wb.Sheets(1)
    
        'do stuff here
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with some excel code that I am having trouble getting
I have created a report in MS Access report and write some VBA code
I have a problem with my VBA code in an excel spreadsheet containing orders.
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem when I try insert some data to Informix TEXT column via
I have a problem with calling the Match function from a VBA code: it
I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on
I have an Excel file that has a bunch of VBA and macro code
I have a problem with my VBA script in Excel. What I do is
I have problem in some JavaScript that I am writing where the Switch statement

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.