+ Reply to Thread
Results 1 to 6 of 6

VBA Problem

  1. #1
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196

    VBA Problem

    Hello,

    I was writing a few learners codes at work (such as activating message & input boxes), and everything works fine when I close and reopen a workbook.

    I tried for the first time at home on two new computers (windows XP home edition), and it doesn't work. The only thing that does happen, is the enable/disable message box comes up, but not my programmed message box.

    Sub GetName()
    returnvalue = InputBox("Enter Name", "Information")
    Sheets("1").Range("B1") = returnvalue
    End Sub


    Note: My macro security is set to medium. At work, our Engineers program things all the time, and maybe something is set to cause the vba codes to work.
    What am I overlooking on my machines?

    Thanks

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    Do you get any errors when you run your code?

    When I ran it, I crashed because I don't have a sheet named "1". I do, however, have a sheets(1), which is also Sheets("Sheet1")

    Ron

  3. #3
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196

    vba reply

    No it doesn't crash. I tried it with both Sheets(1) and Sheets("1"), and the workbook opened find, after selecting enable macros, as I mentioned before. But I just don't see the box pop up for data entry.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    After the workbook is opened and macros are engaged, are you expecting the GetName macro to start running immediately without selecting Tools>Macro>Macros>GetName and clicking [Run]?

    Ron

  5. #5
    Forum Contributor
    Join Date
    05-09-2005
    Location
    SC
    Posts
    196

    VBA code

    Thanks Ron,

    I found out my problem.

    What I did was, hit insert, then selected "module" from the top tool bar in VBA, and for some reason this didn't work. The top bar of the module read Book1 - module 1 (code).

    I compared the two VBA setups when I got back to work, and found out that I should have right clicked on "ThisWorkbook" in the project window in VBA, then selected view code, then enter the code there. The top bar of that module reads Book1 - Thisworkbook (code).

    When I did that, everything worked out fine.
    Note: I can see that like somethings VBA coding is very particular!!!

    Thanks for your help.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    I'm glad you figured it out.

    Regards,
    Ron

+ 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