Public/Private Scope - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Public/Private Scope

SpecialEdSpecialEd Posts: 4Member
[b][red]This message was edited by SpecialEd at 2007-2-7 20:51:13[/red][/b][hr]
I am filling array variables with spreadsheet data and then using various procedures to do calculations. Using different command buttons to do different computations. What is the most efficient way to declare variables so that they are available to all worksheets in the workbook? I have tried all the DIM statements in Public Sub Workbook_Open() but it's not working. My command button gives "Compile error. Sub or function not defined" and the first reference to an array variable in my click event sub is highlighted. I read about modules and tried that but how do I create the module so that it is run at the start?

Thanks for the help.



Comments

  • PavlinIIPavlinII Posts: 404Member
    : [b][red]This message was edited by SpecialEd at 2007-2-7 20:51:13[/red][/b][hr]
    : I am filling array variables with spreadsheet data and then using various procedures to do calculations. Using different command buttons to do different computations. What is the most efficient way to declare variables so that they are available to all worksheets in the workbook? I have tried all the DIM statements in Public Sub Workbook_Open() but it's not working. My command button gives "Compile error. Sub or function not defined" and the first reference to an array variable in my click event sub is highlighted. I read about modules and tried that but how do I create the module so that it is run at the start?
    :
    : Thanks for the help.
    :
    :
    :
    :
    Hi,
    run excel, open VBA editor.
    Menu/Insert/Module - now, you've add empty module called module1 (you can rename it in Properties window).
    Write this into your module
    [code]Public MyVar As String

    Public Sub DoSomething
    MsgBox "I'm doing something"
    DoNohting
    End Sub

    Private Sub DoNothing

    End Sub[/code]
    and MyVar is variable that will be visible from each worksheet in your workbook, and procedure DoSomething is also visible for all.
    Procedure DoNothing is private and can be called ONLY from withing Module1.

    Hope this helps

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.