• Ref to Wkbk Open Event (2003)

    • This topic has 7 replies, 3 voices, and was last updated 17 years ago.
    Author
    Topic
    #451069

    I have set a workbook open event to capture 2 names ‘MyName’ & ‘BossName’ using:

    Private Sub Workbook_Open()
    MyName = InputBox(“Enter Your Name”)
    BossName = InputBox(“Enter Your Line Managers Name”)
    End Sub

    I then want to reference the names in severeral worksheet ranges using =MyName & = BossName but am getting #NAME?

    I know that I am being DULL here but please aleviate my pain!

    Viewing 1 reply thread
    Author
    Replies
    • #1109615

      How are MyName and BossName defined? Are they declared as global VBA variables in a code module, or are they defined names specified in Insert | Name | Define?
      You can’t refer directly to VBA variables in a worksheet formula, and although you can assign the value of defined names using code, you cannot do treat them as if they’re variables.

    • #1109616

      If the names are created with Insert – name -define, you can use:

      Private Sub Workbook_Open()
      range(“MyName”) = InputBox(“Enter Your Name”)
      range(“BossName”) = InputBox(“Enter Your Line Managers Name”)
      End Sub

      Steve

      • #1109620

        Thanks both, I failed to define the names. [stooooopid] Got it sorted now though!

        • #1109621

          How difficult would it be to strengthen this? I would like to remove the cancel option, and on clicking ok, build in error handler so that 2 names (first and surmame) must be input before proceeding? Also could this be done in one dialogue box instead of 2? I’m not sure if this can be achieved?

          • #1109622

            You can create a userform in the Visual Basic Editor with 2 text boxes and a command button with caption OK. The On Click event procedure for the command button would check whether the user has entered data, and if so, store the values and close the userform.
            The Workbook_Open event procedure would simply show the userform.

    Viewing 1 reply thread
    Reply To: Ref to Wkbk Open Event (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: