• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA error 2147024809

geotzi

New Member
Hi,

I have attached a VBA code which creates a run time error 2147024809(80070057).
I still can not find a solution to this error.
Could you please help me to resolve the error?

Thanks
Georgia.
 

Attachments

  • Code.txt
    10.5 KB · Views: 6

Hi !

Seems a bad logic …

But first, in which line error occurs ?‼
Explain the code purpose …
 
Hi !

Seems a bad logic …

But first, in which line error occurs ?‼
Explain the code purpose …
Hi,

The error occurs " exo_wsheet.ChartObjects(ChartName).Chart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture "

So the logic is that the macro creates a presentation with some graphs.
A ppt opens and some graphs are copied & pasted in the presentation deck. The number, names and the format of the graphs are predefined ranges in the workbook.
 
Does the VB error message give any other details? (Syntax, Subscript, Object undefined, etc.)
 
Hi Georgia ,

Resolving this problem is so easy if the workbook with the code is uploaded ; debugging an error , especially a Run Time Error is that much more difficult , since a lot of RTEs can be due to the data.

A lot of time will be spent in various members making suggestions which you will either confirm or reject.

This particular error has so many reasons , one of which can be the chart name ; can you say what is the value of the variable l when this error occurs i.e. does this error occur in the first pass through the For loop or is it after some iterations through the loop ?

What does the variable ChartName contain when the error occurs ? Does this chart exist in the worksheet ?

Narayan
 
Hi Georgia ,

Resolving this problem is so easy if the workbook with the code is uploaded ; debugging an error , especially a Run Time Error is that much more difficult , since a lot of RTEs can be due to the data.

A lot of time will be spent in various members making suggestions which you will either confirm or reject.

This particular error has so many reasons , one of which can be the chart name ; can you say what is the value of the variable l when this error occurs i.e. does this error occur in the first pass through the For loop or is it after some iterations through the loop ?

What does the variable ChartName contain when the error occurs ? Does this chart exist in the worksheet ?

Narayan

The MsgBox ChartName gives me the name of each chart (Chart1, Chart2, Chart3..etc Chart6).The value of the ChartName is predefined in a table(chart_list2) When the loop is ending it shows a blank message for the ChartName Value.

When the error occurs the I variable takes the value 9 and then i receive the attached error message. In the end of this loop I have 10 slides with the last one to be blank. hope that this will help & thanks for the help

Just a note the graphs are 6 in my example but there are 3 slides by default when the ppt opens
 

Attachments

  • Capture.PNG
    Capture.PNG
    8.3 KB · Views: 1
Just curious, can you try copying the entire chart object, not just the chart?
Code:
exo_wsheet.ChartObjects(ChartName).CopyPicture Appearance:=xlScreen,  Format:=xlPicture
 
Just curious, can you try copying the entire chart object, not just the chart?
Code:
exo_wsheet.ChartObjects(ChartName).CopyPicture Appearance:=xlScreen,  Format:=xlPicture

Hi, i tried it but i am still taking the same error.
 
Hmm. Okay, trying to debug. Can you replace the problem line with this
Code:
                    Dim ch As Chart
                    Set ch = exo_wsheet.ChartObjects(ChartName).Chart
                    'Debug info
                    MsgBox "Sheet is: " & exo_wsheet.Name
                    MsgBox "Chart Object is: " & ChartName
                    MsgBox "Chart Item is: " & ch.Name
                   
                   
                    ch.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
and let us know what the 3 messages say, if anything unusual
 
Hmm. Okay, trying to debug. Can you replace the problem line with this
Code:
                    Dim ch As Chart
                    Set ch = exo_wsheet.ChartObjects(ChartName).Chart
                    'Debug info
                    MsgBox "Sheet is: " & exo_wsheet.Name
                    MsgBox "Chart Object is: " & ChartName
                    MsgBox "Chart Item is: " & ch.Name
                  
                  
                    ch.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
and let us know what the 3 messages say, if anything unusual

Hello,

the MsgBox gives the following results:

Sheet is: Charts
Chart Object is: Chart1
Chart item is: Charts Chart1

the loop runs 6 times and gives the right MSgbox messages.

I receive again the same error and the debug now indicates the line

"Set ch = exo_wsheet.ChartObjects(ChartName).Chart"

Tnx,

Georgia
 
Ok...so 6 of the charts are able to get copied correctly, but then errors out on 7th? When it crashes, can you hover your cursor over the CHartName variable, and see what is displayed. Is there someway perhaps the VB is getting a bad name?
 
Ok...so 6 of the charts are able to get copied correctly, but then errors out on 7th? When it crashes, can you hover your cursor over the CHartName variable, and see what is displayed. Is there someway perhaps the VB is getting a bad name?

Yes the total number of charts are 6 which are copied correctly.The MsgBox ChartName gives me Chart1 Chart2.. and Chart6 and the last msgbox is blank.

Do you think that error occus because the loop runs one more time and there is no object to add in the slide. ( So the macro creates 7 slides in total and the last one is blank)
 
Could be...sounds like we're on a right track. How many rows are in this table?
Code:
For Each exo_listrow_cht In config.ListObjects("chart_list2").ListRows
Is there maybe an extra blank row that is causing problems? Or something odd?
 
Could be...sounds like we're on a right track. How many rows are in this table?
Code:
For Each exo_listrow_cht In config.ListObjects("chart_list2").ListRows
Is there maybe an extra blank row that is causing problems? Or something odd?

Hi,

the are more than 6 lines but are blank. I am not sure what i should do ..
 
First idea would be to remove the blank lines, if possible.

Alternative idea is to add an If statement to check if ChartName is blank. First idea:
Code:
For Each exo_listrow_cht In config.ListObjects("chart_list2").ListRows
    ChartNo = exo_listrow_cht.Range.Cells(1, exo_listcol_cht("Chart_No").Index).Value
    ChartName = exo_listrow_cht.Range.Cells(1, exo_listcol_cht("Chart_name").Index).Value
    ChartField = "chart_tbl16"
    '=============
    'NEW LINE HERE
    '=============
    If ChartName = "" Then GoTo SkipRow
    Set exo_listcol_fld = config.ListObjects(ChartField).ListColumns
    l = l + 1
    Set ppo_slide = ppo_pres.Slides.AddSlide(ppo_app.ActivePresentation.Slides.Count + 1, ppo_ctpl)
    exo_wsheet.ChartObjects(ChartName).Chart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
    ppo_app.ActivePresentation.Slides(l).Shapes.Paste
       
    For Each exo_listrow_fld In config.ListObjects(ChartField).ListRows
        'exo_wsheet.Range(exo_listrow_fld.Range.Cells(1, exo_listcol_fld("rangename").Index).Value).CopyPicture Appearance:=xlScreen, Format:=xlPicture
        exo_wsheet.Range(exo_listrow_fld.Range.Cells(1, exo_listcol_fld("rangename").Index).Value).Copy
        ppo_slide.Select
        i = ppo_app.ActivePresentation.Slides(l).Shapes.Count
        ppo_app.ActivePresentation.Slides(l).Shapes.PasteSpecial , , , , , msoTrue
        'ppo_app.ActivePresentation.Slides(l).Shapes.Paste
        Set ppo_shape = ppo_app.ActivePresentation.Slides(l).Shapes(i + 1)
        Application.CutCopyMode = False  'clear the clipboard
        ppo_shape.Name = exo_listrow_fld.Range.Cells(1, exo_listcol_fld("ShapeName").Index)
        ppo_shape.Top = exo_listrow_fld.Range.Cells(1, exo_listcol_fld("top").Index)
        ppo_shape.Left = exo_listrow_fld.Range.Cells(1, exo_listcol_fld("left").Index)
    Next
'BOUNCES TO HERE
SkipRow:
Next
 
Back
Top