Results 1 to 13 of 13

Thread: Runtime Error '9' - HELP!

  1. #1

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Runtime Error '9' - HELP!

    Hi All,

    I'm new to the forum, this is my first post (hope in the right place)... It's my first week at a job, and already I've encountered a serious problem with a macro tied to a number of spreadsheets in an investment company. The previous programmer has left without any notes or documentation - and I'm no good at programming! I'm loosing hair. Here's the issue i'm getting with the code...



    Code:
    Public Sub Auto_Open()
    wrkbkName = Application.ActiveWorkbook.Name
    
    'this little snippet of code determine which branch the user is at
    'based on the ip address
    
    'if ip is like 192.168.1.xxx then we on welthsrvr
    ipadrr = GetIPAddresses(True)
    
    If Left(ipadrr, 9) = "192.168.1" Then
    
    addin_server = "\\Welthsrvr"
    
    ElseIf Left(ipadrr, 9) = "192.168.2" Then
    
    addin_server = "\\Welthsrvr-h"
    Else
    MsgBox "not at either branch"
    End If
    
    addin_full_path = addin_server & addin_path
    
    'I've added a direct path but still no resolution
    
    'AddIns.Add Filename:=addin_full_path, CopyFile:=False
    AddIns.Add ("\\Welthsrvr-h\INDIVIDUAL NON PROPRIETORY ACCOUNTS ON Senior Financial Analyst\Client Accounts\Client Optimizations\client_UDFs.xla"), CopyFile:=False
    
    
    Pub
    AddIns("client_UDFs").Installed = True
    
    Application.Run ("client_UDFs.xla!OpenFiles")
    
    Application.Run "client_UDFs.xla!Shares_Remaining_MarketPrice", wrkbkName
    'Application.Run ("client_UDFs.xla!Summary_TimePeriod")
    Application.Run ("client_UDFs.xla!Update_ProjectionSheet")
    Application.Run ("client_UDFs.xla!Chk4Pref")
    Application.Run ("client_UDFs.xla!ChkInflation")
    Application.Run ("client_UDFs.xla!ChkIndex")
    Application.Run ("client_UDFs.xla!chk6MnthROI")
    Application.Run ("client_UDFs.xla!UpdateSummarySheet")
    Application.Run ("client_UDFs.xla!CloseFiles")
    
    MsgBox "Update Complete", vbInformation
    
    
    
    End Sub



    Code:
    The line of code that results the error:
    
    Sub Auto_close()
    AddIns("client_UDFs").Installed = False
    
    End Sub

    Thanks for any help,

    NICOLE
    Last edited by Nicole.Q; Oct 30th, 2008 at 09:50 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Runtime Error '9' - HELP!

    Welcome to the forums.

    Error 9 is "Subscript Out Of Range" which seems to be what Excel throws at you for a wide variety of reasons (personnally, I think it gets thrown when Excel doesn't know what else to throw )

    Lets start with: what is "AddIns"? Is it the name of a workbook?

  3. #3

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    Hi Hack,

    Thanks for the swift reply and info

    Addins seems to be the part of a workbook (or not) from the add in ribbon menu:

    Code:
    Global wrkbkName As String
    Public addin_full_path As String
    Public Const addin_path = "\INDIVIDUAL NON PROPRIETORY ACCOUNTS ON Senior Financial Analyst\Client Accounts\Client Optimizations\client_UDFs.xla"
    Please correct me if I seem wrong.
    Last edited by Nicole.Q; Oct 30th, 2008 at 12:22 PM.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Runtime Error '9' - HELP!

    addins is the addin collection
    from msdn
    A collection of AddIn objects that represents all the add-ins available to Microsoft Excel, regardless of whether they’re installed. This list corresponds to the list of add-ins displayed in the Add-Ins dialog box (Tools menu).
    to reference the addin by name seems to generate the error, you need to try using its title, which may be the same or different, also if the addin has previously been removed from the collection, you will also get the same error
    to test if the addin is in the collection, and installed, you can run a code like this
    vb Code:
    1. For Each a In AddIns
    2.     If a.Name = "test.xla" Then
    3.     MsgBox a.Title & " installed = " & a.Installed
    4.     End If
    5. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    thanks westconn - i will have to try this in the morning as i am not allowed to carry the files home...

    i will let you know what comes of it, but thanks again!


  6. #6

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    I seem to have sorted out this problem - the 'client_UDFs' xla file was not installed as an addin. after installing it through the add in tool, things seem to look good...

    oh but not yet...

    i'm having a problem with a related spreadsheet. i get the same error except this time the debugger highlights this LOC.

    Code:
    Private Function GetCol4IndexSymbol(ind)
    Dim last_row, col, Index
        'get last row for symbols
        last_row = Workbooks("LOCAL STOCKS.xls").Sheets("Sheet4").UsedRange.Rows.Count
        'get security from selected item
        Index = Search4Cell(ind, "Sheet4", "E", "1", last_row)
        col = Sheets("Sheet4").Range(Index).Offset(0, 1)
        GetCol4IndexSymbol = col
    End Function

  7. #7
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Runtime Error '9' - HELP!

    To slip in -> if it is the same error or type of error then its trying to reference something that is not there.

    so is the work book it is using open? (LOCAL STOCKS.xls)
    Is there sheet 4 in that workbook?

    Can you recod the whole thing with docs to make it work better heheh

    Hope you can get it sorted

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  8. #8

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    Hi Ecniv

    there is a workbook called LOCAL STOCKS, and yes it contains a sheet 4 within it... so it's seems as though i'm pulled into a circle.

    Thanks for the good wishes

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Runtime Error '9' - HELP!

    There is no path information in the call. Is LOCAL STOCKS.xls in the same folder as the excel file trying to call it?

  10. #10

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    no it isn't - but it has been mapped within the previous statement i.e

    AddIns.Add ("\\Welthsrvr-h\INDIVIDUAL NON PROPRIETORY ACCOUNTS ON Senior Financial Analyst\Client Accounts\Client Optimizations\client_UDFs.xla"), CopyFile:=False

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Runtime Error '9' - HELP!

    don't need path for open workbook name within collection

    you don't specify what version of excel your clients are using, is it possible that they have upgraded to 2007?

    for testing purposes you can add code to loop through all open workbooks to return the name, then work with that workbook object
    vb Code:
    1. dim wb as workbook
    2. for each wb in workbooks
    3.   if wb.name = "Local Stocks" then
    4.     last_row = wb.Sheets("Sheet4").UsedRange.Rows.Count
    5.   end if
    6. next
    you can do similar for the sheets, this at least can help you track the problem
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    New Member Nicole.Q's Avatar
    Join Date
    Oct 2008
    Posts
    8

    Re: Runtime Error '9' - HELP!

    Thanks westconn, i will try that

    the employees switched from 2003 to 2007, but apparently some are still using 2003 but saving it to a 2003 format.

    I've made light of some errors - some of the functions within the workbook are fine - but others with the same pathname 'Clients_UDFs.xla' don't seem to function - here's the code in that module:

    Code:
     AddIns.Add ("\\Welthsrvr-h\INDIVIDUAL NON PROPRIETORY ACCOUNTS ON Senior Financial Analyst\Client Accounts\Client Optimizations\client_UDFs.xla"), CopyFile:=False
        
        
    
    'Pub
        AddIns("client_UDFs").Installed = True
        
        Application.Run ("client_UDFs.xla!OpenFiles")
    
    
        Application.Run "client_UDFs.xla!Shares_Remaining_MarketPrice", wrkbkName
        'Application.Run ("client_UDFs.xla!Summary_TimePeriod")
        Application.Run ("client_UDFs.xla!Update_ProjectionSheet")
    
        Application.Run ("client_UDFs.xla!Chk4Pref")
        Application.Run ("client_UDFs.xla!ChkInflation")
        Application.Run ("client_UDFs.xla!ChkIndex")
        Application.Run ("client_UDFs.xla!chk6MnthROI")
    
        Application.Run ("client_UDFs.xla!UpdateSummarySheet")
    
        Application.Run ("client_UDFs.xla!CloseFiles")
        
        MsgBox "Update Complete", vbInformation
        
       
        
    End Sub
    
    Public Sub GAM()
        Application.Run ("client_UDFs.xla!Shares_Remaining_MarketPrice")
    End Sub
    
    Sub Auto_close()
    
        AddIns("client_UDFs").Installed = False
        
    End Sub
    
    Public Sub UpdateSharesRemaining_AfterPurchase()
        Application.Run ("client_UDFs.xla!UpdateSharesRemaining_AfterPurchase")
    End Sub
    
    Public Sub UpdateSharesRemaining_AfterSold()
        Application.Run ("client_UDFs.xla!UpdateSharesRemaining_AfterSold")
    End Sub
    
    Public Sub Calculate_Risk_Profile()
        Application.Run ("client_UDFs.xla!Calculate_Risk_Profile")
    End Sub
    
    Public Sub Populate_RiskProfile()
        Application.Run ("client_UDFs.xla!Populate_RiskProfile")
    End Sub
    
    
    Public Sub UpdateFile()
    
        Application.Run ("client_UDFs.xla!Shares_Remaining_MarketPrice")
        Application.Run ("client_UDFs.xla!Summary_TimePeriod")
        Application.Run ("client_UDFs.xla!Update_ProjectionSheet")
        
    End Sub
    Public Sub UpdateDividendSchedule()
        Application.Run ("client_UDFs.xla!UpdateDividendScedule")
        Application.Run ("client_UDFs.xla!UpdateDividendDates")
        Application.Run ("client_UDFs.xla!UpdateDividendPrices_Purchased")
        Application.Run ("client_UDFs.xla!UpdateDividendPrices_Sold")
        Application.Run ("client_UDFs.xla!UpdateTotals")
        
        MsgBox "Completed"
        
    End Sub
    the line highlighted in red seems to cause my problem error....

    hope i'm not being too much of a headache here...

    Nicole

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Runtime Error '9' - HELP!

    there have been several threads here that workbooks or sheets or other collectios do not always work correctly in 2007, when trying to return members by name, i have not seen any specific solutions given to this problem and as i do not have office 2007 i can not test any of the problems, and i do not understand why it can work sometimes and not others

    the only solution i can offer, but don't really like is to write a function to return the index of the xla, then use the index, similar to the codes i posted above
    vb Code:
    1. Function addingetindex(sname As String)
    2. Dim a As AddIn
    3.   For i = 1 To AddIns.Count
    4.      If AddIns(i).Name = sname Then addingetindex = i: Exit For
    5.      ' note with addins use may need to use title instead of name
    6.  Next
    7. End Function
    8. Sub aa()
    9. x = False
    10. x = AddIns(addingetindex("test.xla")).Installed
    11. End Sub
    you can use similar code to return the index from any collection
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width