|
-
Oct 30th, 2008, 09:29 AM
#1
Thread Starter
New Member
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.
-
Oct 30th, 2008, 09:43 AM
#2
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?
-
Oct 30th, 2008, 09:48 AM
#3
Thread Starter
New Member
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.
-
Oct 30th, 2008, 04:10 PM
#4
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:
For Each a In AddIns If a.Name = "test.xla" Then MsgBox a.Title & " installed = " & a.Installed End If 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
-
Oct 30th, 2008, 09:10 PM
#5
Thread Starter
New Member
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!
-
Oct 31st, 2008, 06:52 AM
#6
Thread Starter
New Member
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
-
Oct 31st, 2008, 07:34 AM
#7
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
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...
-
Oct 31st, 2008, 07:42 AM
#8
Thread Starter
New Member
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
-
Oct 31st, 2008, 07:47 AM
#9
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?
-
Oct 31st, 2008, 11:52 AM
#10
Thread Starter
New Member
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
-
Oct 31st, 2008, 03:16 PM
#11
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:
dim wb as workbook for each wb in workbooks if wb.name = "Local Stocks" then last_row = wb.Sheets("Sheet4").UsedRange.Rows.Count end if 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
-
Nov 3rd, 2008, 08:22 AM
#12
Thread Starter
New Member
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
-
Nov 3rd, 2008, 03:51 PM
#13
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:
Function addingetindex(sname As String) Dim a As AddIn For i = 1 To AddIns.Count If AddIns(i).Name = sname Then addingetindex = i: Exit For ' note with addins use may need to use title instead of name Next End Function Sub aa() x = False x = AddIns(addingetindex("test.xla")).Installed 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|