Print a Message Box
VBA Telemetry pings you when your VBA projects fail
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Print a Message Box

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Is there anyway to do this. I have a message Box that displays the results of a procedure and I would like to give the user an option to print the message box.

    I don't want to pollute any worksheets with the data as a quickfix.

    I found the method PrintForm, but it seems to only work with UserForms.

    Tim.

  2. #2
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,240
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Tim,

    I don't believe there is a way to print a message box, but you can print the text contained in the messagebox using the Shell Print command:

    Dim MessageText As String
    Dim Answer As Variant

    MessageText = "This is a message" & vbCrLf _
    & "If you would like to print it, select Yes" & vbCrLf _
    & "If not, select No"

    Answer = MsgBox(MessageText, vbInformation + vbYesNo, _
    "A Message From Our Sponsor")

    If Answer = vbYes Then
    Open "c:tempmsg.txt" For Output As #1
    Print #1, MessageText
    Close
    Shell "print /d:\AST-P-SSB02ssna-418-lex c:tempmsg.txt"
    Application.Wait Now + 2 / 86400 'wait two seconds for Shell completion
    Kill "c:tempmsg.txt"
    End If

    where

    \AST-P-SSB02ssna-418-lex

    is the name of the print device (in my case, a network printer).

    As you can see, the code writes the data to a temporary file, prints it, then deletes the file.
    Keep Excelling.

    Damon

    VBAexpert Excel Consulting
    LinkedIn Profile http://www.linkedin.com/pub/damon-ostrander/7/79/a93
    AllExperts Profile http://www.allexperts.com/ep/1059-30...-Ostrander.htm

  3. #3
    Board Regular Farah's Avatar
    Join Date
    Oct 2005
    Location
    Lebanon
    Posts
    98
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    do you necessarily have to mention a printer name ? it might be different for users.

  4. #4
    MrExcel MVP
    Join Date
    Apr 2002
    Location
    Vancouver BC , Canada
    Posts
    6,259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I found the method PrintForm, but it seems to only work with UserForms.
    Farah...
    Since you've already discovered the PrintForm method for a userform why not just make a userform that looks like a message box and then give the user the option to print it out ?
    <MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee>

  5. #5
    MrExcel MVP parry's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    3,355
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Hi Tim, you've already got some useful answers to your question but if your wanting to provide feedback to users you could of course post the results into a sheet as part of your code. That way the results are in electronic form rather than a piece of paper.

    A low tech alternative to print an object on the screen is to advise users to use ALT+PRTSCN (for the message box alone, as opposed to PRTSCN for the whole screen) and paste into Word and print.

    hth

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com