Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Run-time Error 9: Subscript out of range

I am working on a new workstation with a Word macro that opens an Excel
spreadsheet and copies a chart into Word. The chart to be copied could
be one of two names -- and the code used for checking works on other
workstations but not mine for some reason.

--snip--
1: On Error Resume Next
2: Set GraphExists = xlApp.Charts("Units Graph")
3:
4: If Err = 0 Then
5: ChartExists = True
6: Else
7: ChartExists = False
8: End If
9:
10:
11:If ChartExists = True Then
12: xlApp.Charts("Units Graph").Select
13: chTitle = "Unit Production Forecast"
14: chNameTab = "Units Graph"
15: GoTo CopyGraph
16:Else
17: xlApp.Charts("Funding Graph").Select
18: chTitle = "Funding Production Forecast"
19: chNameTab = "Funding Graph"
20: GoTo CopyGraph
21:End If
22:
23:CopyGraph:
....
--snip--


The Excel spreadsheet being opened has a chart named Funding Graph. On
other workstations it seems to faily silently and go to the Else
statement at line 16, but on one specific one it fails with "Run-time
Error 9: Subscript out of range" (because "Units Graph" does not
exist).

My question is: is there a setting on the workstation/ in Office etc
that may cause this code to work ok in some situations and throw an
exception in others? As a temporary workaround I have begun to
reference the chart by number as opposed to name, but may not always be
the first chart in a spreadsheet so would appreciate any insight into
why this may be happening or a way to cleanly check for a graph
existing (have researched this but not seen an obvious method -- this
may be a stupid question).

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run-time Error 9: Subscript out of range

With your workbook the active project in the VBE, then
in the vbe, go to Tools=Options and under the general tab make sure you have

Break on Unhandled errors
checked instead of
Break on All Errors.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

I am working on a new workstation with a Word macro that opens an Excel
spreadsheet and copies a chart into Word. The chart to be copied could
be one of two names -- and the code used for checking works on other
workstations but not mine for some reason.

--snip--
1: On Error Resume Next
2: Set GraphExists = xlApp.Charts("Units Graph")
3:
4: If Err = 0 Then
5: ChartExists = True
6: Else
7: ChartExists = False
8: End If
9:
10:
11:If ChartExists = True Then
12: xlApp.Charts("Units Graph").Select
13: chTitle = "Unit Production Forecast"
14: chNameTab = "Units Graph"
15: GoTo CopyGraph
16:Else
17: xlApp.Charts("Funding Graph").Select
18: chTitle = "Funding Production Forecast"
19: chNameTab = "Funding Graph"
20: GoTo CopyGraph
21:End If
22:
23:CopyGraph:
....
--snip--


The Excel spreadsheet being opened has a chart named Funding Graph. On
other workstations it seems to faily silently and go to the Else
statement at line 16, but on one specific one it fails with "Run-time
Error 9: Subscript out of range" (because "Units Graph" does not
exist).

My question is: is there a setting on the workstation/ in Office etc
that may cause this code to work ok in some situations and throw an
exception in others? As a temporary workaround I have begun to
reference the chart by number as opposed to name, but may not always be
the first chart in a spreadsheet so would appreciate any insight into
why this may be happening or a way to cleanly check for a graph
existing (have researched this but not seen an obvious method -- this
may be a stupid question).

Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Run-time Error 9: Subscript out of range

Break on Unhandled errors seems to have already been checked.

Thanks for the quick response though.

1
Tom Ogilvy wrote:
With your workbook the active project in the VBE, then
in the vbe, go to Tools=Options and under the general tab make sure you have

Break on Unhandled errors
checked instead of
Break on All Errors.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

I am working on a new workstation with a Word macro that opens an Excel
spreadsheet and copies a chart into Word. The chart to be copied could
be one of two names -- and the code used for checking works on other
workstations but not mine for some reason.

--snip--
1: On Error Resume Next
2: Set GraphExists = xlApp.Charts("Units Graph")
3:
4: If Err = 0 Then
5: ChartExists = True
6: Else
7: ChartExists = False
8: End If
9:
10:
11:If ChartExists = True Then
12: xlApp.Charts("Units Graph").Select
13: chTitle = "Unit Production Forecast"
14: chNameTab = "Units Graph"
15: GoTo CopyGraph
16:Else
17: xlApp.Charts("Funding Graph").Select
18: chTitle = "Funding Production Forecast"
19: chNameTab = "Funding Graph"
20: GoTo CopyGraph
21:End If
22:
23:CopyGraph:
....
--snip--


The Excel spreadsheet being opened has a chart named Funding Graph. On
other workstations it seems to faily silently and go to the Else
statement at line 16, but on one specific one it fails with "Run-time
Error 9: Subscript out of range" (because "Units Graph" does not
exist).

My question is: is there a setting on the workstation/ in Office etc
that may cause this code to work ok in some situations and throw an
exception in others? As a temporary workaround I have begun to
reference the chart by number as opposed to name, but may not always be
the first chart in a spreadsheet so would appreciate any insight into
why this may be happening or a way to cleanly check for a graph
existing (have researched this but not seen an obvious method -- this
may be a stupid question).

Thanks in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run-time Error 9: Subscript out of range

You checked on the problematic workstation?

you can always loop throught the charts collection and check the names.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

Break on Unhandled errors seems to have already been checked.

Thanks for the quick response though.

1
Tom Ogilvy wrote:
With your workbook the active project in the VBE, then
in the vbe, go to Tools=Options and under the general tab make sure you have

Break on Unhandled errors
checked instead of
Break on All Errors.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

I am working on a new workstation with a Word macro that opens an Excel
spreadsheet and copies a chart into Word. The chart to be copied could
be one of two names -- and the code used for checking works on other
workstations but not mine for some reason.

--snip--
1: On Error Resume Next
2: Set GraphExists = xlApp.Charts("Units Graph")
3:
4: If Err = 0 Then
5: ChartExists = True
6: Else
7: ChartExists = False
8: End If
9:
10:
11:If ChartExists = True Then
12: xlApp.Charts("Units Graph").Select
13: chTitle = "Unit Production Forecast"
14: chNameTab = "Units Graph"
15: GoTo CopyGraph
16:Else
17: xlApp.Charts("Funding Graph").Select
18: chTitle = "Funding Production Forecast"
19: chNameTab = "Funding Graph"
20: GoTo CopyGraph
21:End If
22:
23:CopyGraph:
....
--snip--


The Excel spreadsheet being opened has a chart named Funding Graph. On
other workstations it seems to faily silently and go to the Else
statement at line 16, but on one specific one it fails with "Run-time
Error 9: Subscript out of range" (because "Units Graph" does not
exist).

My question is: is there a setting on the workstation/ in Office etc
that may cause this code to work ok in some situations and throw an
exception in others? As a temporary workaround I have begun to
reference the chart by number as opposed to name, but may not always be
the first chart in a spreadsheet so would appreciate any insight into
why this may be happening or a way to cleanly check for a graph
existing (have researched this but not seen an obvious method -- this
may be a stupid question).

Thanks in advance.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Run-time Error 9: Subscript out of range

I checked on the problematic workstation. Thanks for your help.

Tom Ogilvy wrote:
You checked on the problematic workstation?

you can always loop throught the charts collection and check the names.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

Break on Unhandled errors seems to have already been checked.

Thanks for the quick response though.

1
Tom Ogilvy wrote:
With your workbook the active project in the VBE, then
in the vbe, go to Tools=Options and under the general tab make sure you have

Break on Unhandled errors
checked instead of
Break on All Errors.

--
Regards,
Tom Ogilvy


"Patrick" wrote:

I am working on a new workstation with a Word macro that opens an Excel
spreadsheet and copies a chart into Word. The chart to be copied could
be one of two names -- and the code used for checking works on other
workstations but not mine for some reason.

--snip--
1: On Error Resume Next
2: Set GraphExists = xlApp.Charts("Units Graph")
3:
4: If Err = 0 Then
5: ChartExists = True
6: Else
7: ChartExists = False
8: End If
9:
10:
11:If ChartExists = True Then
12: xlApp.Charts("Units Graph").Select
13: chTitle = "Unit Production Forecast"
14: chNameTab = "Units Graph"
15: GoTo CopyGraph
16:Else
17: xlApp.Charts("Funding Graph").Select
18: chTitle = "Funding Production Forecast"
19: chNameTab = "Funding Graph"
20: GoTo CopyGraph
21:End If
22:
23:CopyGraph:
....
--snip--


The Excel spreadsheet being opened has a chart named Funding Graph. On
other workstations it seems to faily silently and go to the Else
statement at line 16, but on one specific one it fails with "Run-time
Error 9: Subscript out of range" (because "Units Graph" does not
exist).

My question is: is there a setting on the workstation/ in Office etc
that may cause this code to work ok in some situations and throw an
exception in others? As a temporary workaround I have begun to
reference the chart by number as opposed to name, but may not always be
the first chart in a spreadsheet so would appreciate any insight into
why this may be happening or a way to cleanly check for a graph
existing (have researched this but not seen an obvious method -- this
may be a stupid question).

Thanks in advance.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run-time error '9': subscript out of range [email protected] uk Excel Discussion (Misc queries) 4 December 8th 09 10:27 PM
Run time error-subscript out of range ldd Excel Programming 0 March 21st 06 05:37 PM
run-time error '9': Subscript out of range AccessHelp Excel Programming 1 September 30th 05 05:10 PM
Run time error 9 : Subscript out of range JAtz_DA_WAY Excel Discussion (Misc queries) 6 August 29th 05 08:26 PM
Run time error '9' Subscript out of range Tina Excel Programming 1 August 25th 03 02:05 AM


All times are GMT +1. The time now is 02:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"