Need help cleaning up VBA code for add-in

Jarvoisier

New Member
Joined
Aug 29, 2011
Messages
14
For the life of me I can't get this add-in to run...I keep getting error message saying "Run-time error '91': Object variable or With block variable not set."

The goal of this add-in is to run when excel is opened for ANY pre-existing and/or new excel file.

I am a novice to writing code, so I am assuming that I messed something up from the awesome assistance I received from other members of this forum in another thread I had going.

I will post all code as well as links to screen shots on photobucket if people want to see what I am seeing on my VBA screen.

I'm still getting an error message for this darn add-in. I will post code as follows to see if you all can find where the screw up is.

Class Module named cAOpen...this is where the highlighted text is. The highlighted part of the line is "If ActiveWorkbook.Name <> ThisWorkbook.Name Then"...

Code:
Option Explicit
Public WithEvents aOpen As Application
Private Sub aOpen_WorkbookOpen(ByVal Wb As Workbook)
    If ActiveWorkbook.Name <> ThisWorkbook.Name Then MyMacro
End Sub
Private Sub MyMacro()
    Dim wks          As Worksheet
 
    For Each wks In ActiveWorkbook.Worksheets
        wks.Visible = xlSheetVisible
        With wks.PageSetup
            .LeftHeader = ""
            .CenterHeader = "&F"
            .RightHeader = ""
            .CenterFooter = "&A"
            .RightFooter = "Page &P of &N"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.25)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = True
            .PrintTitleColumns = ""
        End With
    Next wks
End Sub

Module1:
Code:
Option Explicit
 
Dim autoOpen As New cAOPen
 
Sub SetAutoOpen()
  Set autoOpen.aOpen = Application
End Sub
 
Sub UnSetAutoOpen()
  Set autoOpen.aOpen = Nothing
End Sub

ThisWorkbook:
Code:
Private Sub Workbook_Open()
  SetAutoOpen
End Sub

Links to screen shots on photobucket:

Class Module cAOpen:
http://i76.photobucket.com/albums/j6/JARVOISIER/ClassModule-cAOPen.jpg

ThisWorkbook:
http://i76.photobucket.com/albums/j6/JARVOISIER/ThisWorkbook-1.jpg

Module1:
http://i76.photobucket.com/albums/j6/JARVOISIER/Module1.jpg

Many thanks in advance for any assistance!!!

RJ
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top