View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
DDawson DDawson is offline
external usenet poster
 
Posts: 59
Default Hard return in textbox for header text

Thanks Steve

I had to add a line to the BeforePrint WorkBook Event so that the data is
cleared before I print.
strTitle = ""

I get the following result when I add the following to the dialog
"1
2
A
B"

Results on print preview is:
"1 2 A B"
Is this what you intended from the code - so that all text appears on one
line? My original problem was that I get an extra blank line between the text
when I print preview, so the result would look something like:
"1

2

A

B"

I just wanted a solution that removes the blank lines so that it is as it
appears in the dialog. E.g.
"1
2
A
B"

Is there any way you can modify your code to solve this, please?

Thanks
Dylan

"Incidental" wrote:

Hi Dylan

The code below is one way to do it. I came across a similar problem
before removing address details from a multiline textbox that i needed
in a single line, what i have done is use the split function to create
an array of the data held in the lines of the textbox and then passed
those lines back out of the array into the string. I hope this helps
you out and sorts your problem, if you need help with the code let me
know and i shall comment it for you. The only other thing i changed
was i added a with statement to the end for the
"ActiveSheet.PageSetup" sections as it is tidier and easier to read
and of course less to type. ;D

Option Explicit
Dim ArrayCount, i As Integer
Dim strTitle As String
Dim SplitArray As Variant

Private Sub btnTitle_Click()

SplitArray = Split(txtTitle.Value, vbNewLine)

ArrayCount = UBound(SplitArray)

For i = 0 To ArrayCount

strTitle = strTitle & SplitArray(i) & " "

Next

With ActiveSheet.PageSetup

..PrintTitleRows = "$1:$1"

..CenterHeader = "&""Arial,Bold""&14 " & _
strTitle & Chr(10) & (Date) & " " & (Time)

..RightHeaderPicture.Filename = "H:\SWS Logo sm.jpg"

..LeftHeader = "&""Arial,Bold""&14&D"

End With
'Print Sheet
' ActiveWindow.SelectedSheets.PrintOut Copies:=1

frmPageTitle.Hide

End Sub

I hope this helps

Steve