• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How Do I Add A Print MsgBox Button (To A MsgBox)?

MsgBox "Hello World", vbOkCancel, "Hello World"


How would I simply add a button to print the message it displays to the default printer?
 
You can't print single messages to the printer, only what's on the worksheet. You can "print" to the immediate window (Ctrl+g) of the VBE if you want.

[pre]
Code:
MyMessage = "HellowWorld"
MsgBox MyMessage
Debug.Print MyMessage
[/pre]
 
Okay I see I see.


Hmm..


What it make any difference if I were using a .vbs windows sript?


I'm creating a simple calculator at work (using a .vbs file actually), just thought it'd be nice if I could print the results from the message box.
 
VBScript code to print using notepad:


Dim objFSO, objText, strText, strFile, objShell


strFile=replace(WScript.ScriptFullName,WScript.ScriptName,"to_print.txt")


strText="Test" 'message that should be printed


Set objShell=WScript.CreateObject("WScript.shell")

Set objFSO=WScript.CreateObject("Scripting.FileSystemObject")


Set objText =objFSO.CreateTextFile(strFile,2)

objText.Write(strText)

objText.Close


objShell.Run "%windir%notepad /p """ & strFile & """",0


WScript.Sleep 1000


objFSO.DeleteFile strFile


Set objText=Nothing

Set objFSO=Nothing

Set objShell=Nothing


WScript.Quit
 
Back
Top