Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referencing trouble in excel
Message
 
To
All
General information
Forum:
Microsoft Office
Category:
Excel
Title:
Referencing trouble in excel
Environment versions
Microsoft Office:
Office 2010
Miscellaneous
Thread ID:
01550398
Message ID:
01550398
Views:
61
Please consider the class below. The "instancing" property is set to "2-PublicNotCreatable"

When I instantiate from the Immediate Window it works.

Yet when I instatiate it in a module of a project that references the library in which the class is located, the compiler gives me a "invalid use of new" error.
Option Explicit
Dim oWB As Workbook
'-----------------------------
Private Sub Class_Initialize()
    Set oWB = Workbooks.Open("P0040" & "Config.XLSX")
    Dim oRng As Range
    Set oRng = oWB.Sheets(1).Range("A1").CurrentRegion
    Dim oName As Name
    For Each oName In Names
        oName.Delete
    Next
    oRng.CreateNames False, True, False, False
End Sub
'--------------------------------------------
Public Function uValue(cConfigName As String)
    uValue = oWB.Sheets(1).Range(cConfigName)
End Function
'--------------------------------------
Public Sub setValue(cConfigName, uValue)
    oWB.Sheets(1).Range(cConfigName) = uValue
End Sub
'----------------------------
Private Sub Class_Terminate()
    oWB.Close False
    Set oWB = Nothing
End Sub

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Next
Reply
Map
View

Click here to load this message in the networking platform