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"...
Module1:
ThisWorkbook:
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
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