Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Error problems

Hiya I have this section of code which takes up to forty charts, identified
by references and pastes them into a word document.

I have an error handling statement which if the chart doesn't exist should
enable the procedure to recover and go on to the next chart.

I am testing the code by giving a reference to a chart that doesn't exist.
Unfortunately the code still crashes with an 1004 error, which I thought
would be trapped.

I do have another error handling code previously in the code but this should
be switched off when it reaches the code shown below.

Can anyone help? I can give more info if needed. Here is the code:


For ChartIdentifierNum = 1 To 40

ChartIdentifier = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 5).Value
ChartReference = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 6).Value

If ChartIdentifier < "" Then

If ChartReference < "" Then

Worksheets("Chart Sheet").Activate

On Error GoTo SkipChart
ActiveSheet.ChartObjects(ChartReference).Select

Selection.Copy

With wdApp
Set MyRange = .ActiveDocument.Content

MyRange.Find.Execute FindText:=ChartIdentifier, Forward:=True

If MyRange.Find.Found = True Then

MyRange.Select

.Selection.PasteSpecial Link:=False,
DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False

End If
End With

SkipChart:

On Error GoTo 0

End If

End If

Next ChartIdentifierNum


TIA!

A confused,

Nick Shinkins



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Error problems

Sorted it myself

Seems you can't have an On Error Goto OnePlace

and another On Error Goto AnotherPlace in the same Sub, even if you have
used On Error Goto 0 in between.

So I just farmed out the section of code containg the second on error to
another sub and it works fine.


"Nick Shinkins" wrote:

Hiya I have this section of code which takes up to forty charts, identified
by references and pastes them into a word document.

I have an error handling statement which if the chart doesn't exist should
enable the procedure to recover and go on to the next chart.

I am testing the code by giving a reference to a chart that doesn't exist.
Unfortunately the code still crashes with an 1004 error, which I thought
would be trapped.

I do have another error handling code previously in the code but this should
be switched off when it reaches the code shown below.

Can anyone help? I can give more info if needed. Here is the code:


For ChartIdentifierNum = 1 To 40

ChartIdentifier = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 5).Value
ChartReference = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 6).Value

If ChartIdentifier < "" Then

If ChartReference < "" Then

Worksheets("Chart Sheet").Activate

On Error GoTo SkipChart
ActiveSheet.ChartObjects(ChartReference).Select

Selection.Copy

With wdApp
Set MyRange = .ActiveDocument.Content

MyRange.Find.Execute FindText:=ChartIdentifier, Forward:=True

If MyRange.Find.Found = True Then

MyRange.Select

.Selection.PasteSpecial Link:=False,
DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False

End If
End With

SkipChart:

On Error GoTo 0

End If

End If

Next ChartIdentifierNum


TIA!

A confused,

Nick Shinkins



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Error problems

Maybe you can just check in line and continue depending on what you find:

Option Explicit
Sub testme()

Dim myChartObject As ChartObject
Dim ChartIdentifierNum As Long
Dim ChartIdentifier As Variant
Dim ChartReference As Variant
Dim wdApp As Word.Application
Dim myRange As Word.Range

Set wdApp = New Word.Application
wdApp.Visible = True

wdApp.Documents.Add DocumentType:=wdNewBlankDocument

For ChartIdentifierNum = 1 To 40
ChartIdentifier = Sheets("Report Export Ref").Cells(3 _
+ ChartIdentifierNum, 5).Value
ChartReference = Sheets("Report Export Ref").Cells(3 _
+ ChartIdentifierNum, 6).Value

If ChartIdentifier < "" Then
If ChartReference < "" Then

Set myChartObject = Nothing
On Error Resume Next
Set myChartObject = Worksheets("Chart Sheet") _
.ChartObjects(ChartReference).Select
On Error GoTo 0

If myChartObject Is Nothing Then
'do nothing
Else
myChartObject.Copy
With wdApp
Set myRange = .ActiveDocument.Content
myRange.Find.Execute FindText:=ChartIdentifier, _
Forward:=True
If myRange.Find.Found = True Then
myRange.Select
.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
End If
End With
End If
End If
End If
Next ChartIdentifierNum
End Sub

(I fudged the MSWord stuff.)


Nick Shinkins wrote:

Hiya I have this section of code which takes up to forty charts, identified
by references and pastes them into a word document.

I have an error handling statement which if the chart doesn't exist should
enable the procedure to recover and go on to the next chart.

I am testing the code by giving a reference to a chart that doesn't exist.
Unfortunately the code still crashes with an 1004 error, which I thought
would be trapped.

I do have another error handling code previously in the code but this should
be switched off when it reaches the code shown below.

Can anyone help? I can give more info if needed. Here is the code:

For ChartIdentifierNum = 1 To 40

ChartIdentifier = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 5).Value
ChartReference = Sheets("Report Export Ref").Cells(3 +
ChartIdentifierNum, 6).Value

If ChartIdentifier < "" Then

If ChartReference < "" Then

Worksheets("Chart Sheet").Activate

On Error GoTo SkipChart
ActiveSheet.ChartObjects(ChartReference).Select

Selection.Copy

With wdApp
Set MyRange = .ActiveDocument.Content

MyRange.Find.Execute FindText:=ChartIdentifier, Forward:=True

If MyRange.Find.Found = True Then

MyRange.Select

.Selection.PasteSpecial Link:=False,
DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False

End If
End With

SkipChart:

On Error GoTo 0

End If

End If

Next ChartIdentifierNum

TIA!

A confused,

Nick Shinkins


--

Dave Peterson
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
sorting problems - error message: identically sized merged cells. 4markw Excel Discussion (Misc queries) 2 January 5th 10 06:28 PM
Formula problems that keep producing a #Value! Error!! Danny Boy Excel Worksheet Functions 10 June 21st 09 06:11 PM
File Sharing Problems - Error Message Kristi - Skills Group Excel Discussion (Misc queries) 1 December 17th 04 05:50 PM
Textbox error checK problems Jako[_51_] Excel Programming 1 July 31st 04 10:47 PM
Problems ignoring error message Dr. Schwartz[_3_] Excel Programming 1 February 24th 04 03:26 PM


All times are GMT +1. The time now is 02:48 AM.

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"