Results 1 to 3 of 3

Thread: Simple question from VBA noobie..

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Simple question from VBA noobie..

    Hi,

    for some reason I can not do this because I am new to VBA. How can I get a chart reference be made available in a userform?
    I know module's is where you would want to declare global variables, but I still have a problem there.

    In my spreadsheet:
    VB Code:
    1. Private sub transferChart()
    2.   Sheets("Sheet1").ChartObjects("Chart 1").Activate
    3.   Call toModule(ActiveChart)
    4. End Sub

    In Module:
    VB Code:
    1. Public Function toModule(ByVal mychart As Chart)
    2.   chartA = mychart
    3. End Function
    4. 'userform would call this function to get the chart reference from spreadsheet
    5. Public Function returnChart() As Chart
    6.   returnChart = chartA
    7. End Function

    this way seems kind of tedious. Is there another way, becuase this one isn't working.

  2. #2

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Simple question from VBA noobie..

    btw, my chartA variable is a declared global variable in Module1.
    I also have 'Set chartA = mychart' instead of 'chartA = mychart'
    thanks!!

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Simple question from VBA noobie..

    Code:
    Private sub transferChart()
        toModule Sheets("Sheet1").ChartObjects("Chart 1")
    End Sub
    Once you set it in the module, if you declare the variable to be public, you can just use that variable name from anycode in the forms modules or other modules directly. No need for a return function.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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