Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
sorting problems - error message: identically sized merged cells. | Excel Discussion (Misc queries) | |||
Formula problems that keep producing a #Value! Error!! | Excel Worksheet Functions | |||
File Sharing Problems - Error Message | Excel Discussion (Misc queries) | |||
Textbox error checK problems | Excel Programming | |||
Problems ignoring error message | Excel Programming |