Forum Discussion
Problem with text toolbox in connection with printing
So, now it works !!! Thx.
I have a further question:
How can i print more than one text boxes? I have 5 text boxes in the sheet.
Please tell me the correct vba-config.
Many greets
SteVer1880 That is slightly more complicated as we have to record the heights and widths of all textboxes prior to changing them:
Option Explicit
Dim OldHeights() As Double
Dim OldWidths() As Double
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim Obj As Object
Dim lCt As Long
ReDim OldHeights(1 To 1)
ReDim OldWidths(1 To 1)
If ActiveSheet.Name = "Sheet1" Then
For Each Obj In Sheet1.OLEObjects
If TypeName(Obj.Object) = "TextBox" Then
lCt = lCt + 1
ReDim Preserve OldHeights(1 To lCt)
ReDim Preserve OldWidths(1 To lCt)
With Obj
OldHeights(lCt) = .Height
OldWidths(lCt) = .Width
.Object.AutoSize = True
End With
End If
Next
End If
Application.OnTime Now, "'" & ThisWorkbook.FullName & "'!thisworkbook.ReSizeBox"
End Sub
Public Sub ReSizeBox()
Dim Obj As Object 'msforms.TextBox
Dim lCt As Long
For Each Obj In Sheet1.OLEObjects
If TypeName(Obj.Object) = "TextBox" Then
lCt = lCt + 1
With Obj
.Object.AutoSize = False
.Height = OldHeights(lCt)
.Width = OldWidths(lCt)
End With
End If
Next
End Sub
- JKPieterseJun 24, 2019Silver ContributorExcellent, glad you were able to solve the issue.
- SteVer1880Jun 24, 2019Copper Contributor
Good Morning,
thx for your great support. At the weekend i´m created a form with ms word. I think it is the better way to solve my problems - an what should i say -> it work`s.
I'am thankfull of your help.
Best regard´s
Steffen Verfürth
- JKPieterseJun 21, 2019Silver ContributorTo be honest, I don't know a really solid solution for this. We could:
1. Remember the tops of each textbox and move textboxes 2-n down if needed
2. If a textbox becomes taller than a given number, first remember its width and make it wider before setting it to autosize
Option 1 may mean the textbox spills to a next sheet of paper when printing (Don't even know if the last one will print if it spills over if your print area is too small?)
Option 2 will nog guarantee they don't overlap
Excel is not the best program to use when it comes to printing large amounts of texts. More than ~1000 characters quickly becomes cumbersome. - SteVer1880Jun 21, 2019Copper Contributor
Hi,
thx for the info! So far so good - but there is the next surprise.
The extendet textboxes are overlap. Is there a way to dynamically move the other text in the textboxes an the normal text (in this case "TextBox2")? -> See the Screenshot !
What do you mean - i'm on the right way to create a functionall solution or should i think about my idea idea to realise the form ?
- JKPieterseJun 19, 2019Silver ContributorMove the code to the "Diesearbeitsmappe" module and in the code, replace "Thisworkbook" with "Diesearbeitsmappe".
- SteVer1880Jun 19, 2019Copper Contributor
here it is :-)
- JKPieterseJun 19, 2019Silver ContributorCan you please post the workbook rather than a screenshot?
- SteVer1880Jun 19, 2019Copper Contributor
Thanks for your use!
I have tested the current config, unfortunately it does not work as desired.
A screenshot of the application, the config and the printer result is in the appendix