+ Reply to Thread
Results 1 to 5 of 5

passing arrays to newly created chart module

  1. #1
    Registered User
    Join Date
    07-24-2007
    Posts
    15

    passing arrays to newly created chart module

    I have a macro that creates a chart as a chart sheet from a .csv file. I put the data that I need from the .csv file into a couple arrays.

    Now I want to make a smaller chart object in the chart sheet when a series point is clicked on. I can get it to do this just fine by making use of the following:

    With ActiveWorkbook.VBProject.VBComponents(ChartName).CodeModule
    LineNum = .CountOfLines + 1
    .InsertLines LineNum, "Option Explicit" & Chr(10) & _
    "Private Sub Chart_MouseDown .... ' etc. with a GetChartElement in there.

    My only problem now is that I want the smaller chart to be made based on the arrays that were made in my macro. I've tried just declaring the arrays as Public, but that doesn't seem to work. How do I get the arrays from my macro into the chart module?

    Thanks!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello BRay840,

    Can you show us an example of the macro you used? Be sure to use the Code Tags to wrap your code when posting. If you don't know how click this link Forum Rules

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    07-24-2007
    Posts
    15
    Okay, here's where I'm at now: (my code is waaay too long and unorganized to try to post)

    I was able to do what I want with a smaller test macro and chart sheet by just making my array Public in the macro module.

    I tried this in my actual macro and with adding some breaks and watching the array, when the piece of code that I posted earlier runs (to add text to the chart sheet module) the public array becomes empty again.

    Why is it emptying my public array?
    Is it because I'm using the array in the text I'm adding to the chart sheet code?
    How do I get around this?

  4. #4
    Registered User
    Join Date
    07-24-2007
    Posts
    15
    I've broken down my code a lot and set breakpoints all throughout. And the Public array fills with the data I give it and is there and available. But as soon as I run the code to add text to the CodeModule, my Array value and type become Empty. (Even if the code is only to add 'Option Explicit')

    With ActiveWorkbook.VBProject.VBComponents("Chart2").CodeModule
    LineNum = .CountOfLines + 1
    .InsertLines LineNum, "Option Explicit"
    End With

    Why does it do this? How do I make it stop?!

  5. #5
    Registered User
    Join Date
    07-24-2007
    Posts
    15
    So now when I try to put a Stop anywhere after my .CodeModule lines, I get the "Can't enter break mode at this time" error. So I put a MsgBox just before End Sub of my macro to display some of the data in the array, and it worked.

    So the Public array is clearing once the sub ends??? Why?!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1