+ Reply to Thread
Results 1 to 6 of 6

Custom MsgBox via UserForm, startup position and resizable

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2006
    Location
    South Central Pennsylvania
    MS-Off Ver
    MS Office Pro Plus 2016, on Window 10
    Posts
    27

    Custom MsgBox via UserForm, startup position and resizable

    After searching a lot for a means to define the startup position for a userform, I developed a custom message box via a userform and I would like to share it here.
    It also allows a lot more characters to be displayed and has a bit of emulation for the button styles that are available with the built-in MsgBox.

    All the code for the custom MsgBox is in a UserForm module and for an example of usage, a worksheet with a button and a regular module is also included.

    Edited to attach the Excel file after bumping the Enter key prematurely.

    Regards, Jim
    Attached Files Attached Files
    Last edited by jdawson; 08-09-2019 at 12:25 PM. Reason: Bumped enter key while typing tag values.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Re: Custom MsgBox via UserForm, startup position and resizable

    .
    Just an observation ... there is an error message on this line :

    msg = ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text

  3. #3
    Registered User
    Join Date
    03-06-2006
    Location
    South Central Pennsylvania
    MS-Off Ver
    MS Office Pro Plus 2016, on Window 10
    Posts
    27

    Re: Custom MsgBox via UserForm, startup position and resizable

    I don't get that error. Perhaps something like ThisWorkbook.Worksheets("TheSheetName")... would work better.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Re: Custom MsgBox via UserForm, startup position and resizable

    .
    I am not certain what control is presently located on Sheet1 ... that is named "Textbox 1" .... but it isn't a textbox.

    After inserting an ActiveX textbox onto the sheet and adding some text, the userform does load but is only displaying
    an OK button.

    ???

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Re: Custom MsgBox via UserForm, startup position and resizable

    .
    Disregard the last comment re: only displaying an OK button.

    It is working now after adding the ActiveX textbox.

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Re: Custom MsgBox via UserForm, startup position and resizable

    .
    Also ... here is the edited code :

    Option Explicit
    
    Private Sub TestMsgBox()
        Dim btnStyle As VbMsgBoxStyle
        Dim resp As VbMsgBoxResult
        Dim msg As String
        
        'msg = Replace(Space(1024), " ", "M")
        msg = ActiveSheet.TextBox1.Text
        msg = "Number of characters = " & Len(msg) & vbCrLf & msg
        
        'btnStyle = vbAbortRetryIgnore
        btnStyle = Range("VbMsgBoxStyleSelectedValue")
        
        resp = CustMsgBox.ShowMsgBox(msg, btnStyle, 144)
        
        msg = CustMsgBox.ReturnVal_btnTxt(resp)
        MsgBox "You clicked """ & msg & """"
        
    
    End Sub
    
    Sub Button1_Click()
        TestMsgBox
    End Sub

    Nice job on your project ! Good addition to the Forum that others will find helpful.

    Cheers.

+ 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. User Form Startup Position
    By ldoodle in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2018, 06:25 AM
  2. msgbox startup
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2016, 01:05 PM
  3. VBA for Custom userform position next to a cell
    By amein in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2015, 08:07 AM
  4. [SOLVED] Custom userform position next to a cell
    By amein in forum Excel General
    Replies: 2
    Last Post: 09-09-2015, 07:02 AM
  5. [SOLVED] Userform - startup position
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-23-2014, 01:44 PM
  6. How Do I make a Userform Resizable or allow it to scroll
    By Invicta084 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-25-2014, 06:57 AM
  7. Control Startup Position of UserForm
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2011, 01:31 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