+ Reply to Thread
Results 1 to 6 of 6

MsgBox will freeze program when running script more than once

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Edgewood, New Mexico
    MS-Off Ver
    Excel 2016
    Posts
    6

    MsgBox will freeze program when running script more than once

    Hi,
    I am pretty new to Excel vba. I have run into an error I haven't found any resolution for.
    When I run the script, the message box will pop up and provide me the info. I click OK and it closes.
    But when I run it again, it pops up again, but then the code box as well as MS Excel is frozen.
    I have to force close Excel through task manager to exit.
    Here is the code I have:

    Sub FileName ()

    ' This is a way to get the file name in a messagebox
    ' After clicking OK, the messagebox should close
    ' The filename should not show the file extension

    Dim FileName As String
    FileName = ThisWorkbook.Name
    FileName = Left(FileName, Len(FileName)-5)

    'Variable declaration
    Dim Output as Integer

    'Example vbOKOnly
    Output = MsgBox ("The name of this file is " & FileName, vbOKOnly, "Get file name")

    End Sub

    What am I doing wrong?
    Thanks for any help

    Adutchbrew

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: MsgBox will freeze program when running script more than once

    Nothing wrong with it as far as I can see. I've run it several times without issue.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: MsgBox will freeze program when running script more than once

    Same here, but I would suggest you don't use Filename for the name of the sub and the name of a variable in the sub.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    01-14-2013
    Location
    Edgewood, New Mexico
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: MsgBox will freeze program when running script more than once

    Thank you TMS.
    Not sure what happened. I went back and tried it again and now it works without problem. Don't think I made any revisions compared to before.
    Adutchbrew

  5. #5
    Registered User
    Join Date
    01-14-2013
    Location
    Edgewood, New Mexico
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: MsgBox will freeze program when running script more than once

    Thank you for response Norie.
    Not sure what happened before, but when I run it now, I don't have any issues running the code. Even without making your recommended adjustments.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: MsgBox will freeze program when running script more than once

    No problem, Excel can be temperamental from time to time.


    Anyway, you're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help!? Running/Re-running a SQL Script through Excel (easily?)
    By KOOOP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 02:27 PM
  2. Add-on vba program for resizing and recoloring msgbox fonts
    By omega0010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2012, 08:48 AM
  3. MsgBox problems + reloading script on error
    By OnlyTheSnake in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-04-2011, 09:56 AM
  4. Using VB script to send keystrokes to another program
    By tonymorton@googlemai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-03-2008, 04:18 PM
  5. Change event causes program to freeze
    By KobusD in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-30-2005, 12:05 PM

Tags for this Thread

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