Results 1 to 4 of 4

Thread: Excel charts and macro problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Excel charts and macro problem

    Hi,

    I'm able to run my macro perfectly well in the workbook that the macro is contained in. However, when I try to run it in another workbook, the macro does not run. I get a:
    Run-time error '1004'
    Unable to get the Chart Objects property of the Worksheet class

    This is the line highlighted:
    ActiveSheet.ChartObjects("Chart 2").Activate


    Here is the bunch of code that contains that line:
    ActiveChart.Axes(xlValue).Select
    ActiveChart.ChartArea.Select
    ActiveChart.ChartArea.Copy
    ActiveWindow.Visible = False
    Windows("nmmacrosheet.xls").Activate
    Range("A26").Select
    ActiveSheet.Paste
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartArea.Select
    ActiveWindow.Visible = False
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).XValues = "=graphs!R2C10:R361C10"
    ActiveChart.SeriesCollection(2).XValues = "=graphs!R2C10:R361C10"

    I'd appreciate help with this. I'm guessing that it has to do something with the chart and the workbook.

    Thanks,
    Neil

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel charts and macro problem

    You try to run it in another workbook, does the other workbook contain the macro code in "ITS" ThisWorkbook class?
    If its not in the workbook that your trying to run the macro then it cant see it. Maybe you want to place the macro in your personal
    macro workbook?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Excel charts and macro problem

    what Robb said, or your worksheet does not contain a 'Chart 2' object
    if you fail to plan, you plan to fail

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: Excel charts and macro problem

    Hi,

    Thanks for the advice and I am asking for further.

    When I try to use the personal macro workbook, I get a message:
    Cannot edit a macro in a hidden workbook. Unhide the workbook using the Unhide command.

    However, I can't even find that workbook.

    Also, is there a way to define the other workbook so that I can have the macro go to that one rather than looking for the workbook that I wrote the macro within? Basically, I am taking a bunch of data from a measurement device which yields an unformatted Excel workbook. The macro that I am writing is supposed to format the sheets into something useable including graphs.

    Thanks again,
    Neil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width