Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Put MsgBox text in a worksheet for printing

I have an Excel macro that finishes by displaying several lines of
results in a MsgBox. The output is arranged with the positioning
characters vbTab and vbCr so it aligns neatly.

When I do this in Word, I often give the user the option of printing the
MsgBox's text. It's easy to code -- just add a new document, set its
contents equal to the string that went into the MsgBox, and print. Word
interprets the vbCr and vbTab characters the same way in the MsgBox as
in the document.

Is there an easy way to do the same thing in Excel? -- to create a sheet
of printable results from formated MsgBox content? I know I could
parsing the MsgBox string into cell-shaped units and painstakingly
arrange them on a worksheet, but these messages can have several dozen
vbTab's and vbCR's, and the # of lines and tabs is never constant, so
that could be a huge job.

I've tried loading the MsgBox text into a new sheet's text box
(substituting vbLf's of vbCr's), and also into cell A1 after enlarging
it to fill the screen, but the vbTab characters of course remain ignored
in both cases. Other than a screenshot (which is what we're doing now),
is there a simpler way to handle this with code?

TIA
-----------------------
Mark Tangard
"Life is nothing if you're not obsessed." --John Waters
  #2   Report Post  
Posted to microsoft.public.excel.programming
Zoo Zoo is offline
external usenet poster
 
Posts: 40
Default Put MsgBox text in a worksheet for printing

Try followings:

Sub Main1()
Dim sMsg As String
Dim l1 As Long, l2 As Long
'Create a message.
For l1 = 0 To 9
For l2 = 0 To 9
sMsg = sMsg & (l1 * 10 + l2) & vbTab
Next
sMsg = sMsg & vbCr
Next
MsgBox sMsg

Dim x As Long
Dim y As Long
Dim vY As Variant
Dim vX As Variant
vY = Split(sMsg, vbCr)

On Error Resume Next
For y = LBound(vY) To UBound(vY)
vX = Split(vY(y), vbTab)
Sheet1.Range(Sheet1.Cells(y + 1, LBound(vX) + 1), Sheet1.Cells(y +
1, UBound(vX) + 1)) = vX
Next

End Sub

Sub Main2()
Dim sMsg As String
Dim l1 As Long, l2 As Long
'Create a message.
For l1 = 0 To 9
For l2 = 0 To 9
sMsg = sMsg & (l1 * 10 + l2) & vbTab
Next
sMsg = sMsg & vbCr
Next
MsgBox sMsg

Cells(1, 1) = Replace(Replace(sMsg, vbTab, Space(4)), vbCr, vbLf)
Columns(1).ColumnWidth = 100
End Sub

"Mark Tangard" wrote in message
...
I have an Excel macro that finishes by displaying several lines of
results in a MsgBox. The output is arranged with the positioning
characters vbTab and vbCr so it aligns neatly.

When I do this in Word, I often give the user the option of printing the
MsgBox's text. It's easy to code -- just add a new document, set its
contents equal to the string that went into the MsgBox, and print. Word
interprets the vbCr and vbTab characters the same way in the MsgBox as
in the document.

Is there an easy way to do the same thing in Excel? -- to create a sheet
of printable results from formated MsgBox content? I know I could
parsing the MsgBox string into cell-shaped units and painstakingly
arrange them on a worksheet, but these messages can have several dozen
vbTab's and vbCR's, and the # of lines and tabs is never constant, so
that could be a huge job.

I've tried loading the MsgBox text into a new sheet's text box
(substituting vbLf's of vbCr's), and also into cell A1 after enlarging
it to fill the screen, but the vbTab characters of course remain ignored
in both cases. Other than a screenshot (which is what we're doing now),
is there a simpler way to handle this with code?

TIA
-----------------------
Mark Tangard
"Life is nothing if you're not obsessed." --John Waters


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bold Text In Msgbox FARAZ QURESHI Excel Discussion (Misc queries) 2 April 10th 09 08:26 AM
MsgBox text on several lines mohavv Excel Discussion (Misc queries) 1 November 21st 07 08:17 PM
printing a worksheet with VB buttons or text boxes Pauline Excel Discussion (Misc queries) 1 September 15th 06 01:18 AM
If a worksheet name is = to test then a msgbox appears Vick Excel Discussion (Misc queries) 1 December 21st 05 11:17 PM
VBA MsgBox() Text gkelle[_9_] Excel Programming 2 April 20th 04 08:32 PM


All times are GMT +1. The time now is 05:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"