Need text box to be invisible when printing

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,288
I have a text box that has default text that disappears when you type in the box. What vba code would make the box invisible when printing if it contains the text "Please type notes here"?
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,738
Office Version
2013
Platform
Windows
Use
Code:
textboxname.visible=false
and put it just before the print lines of code
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,288
By having default text, I mean that I have the following code in my spreadsheet:

Code:
Private Sub TextBox1_Change()
TextBox1.Height = TextBox1.Height
'  TextBox1.Width = 540
End Sub


Private Sub TextBox1_GotFocus()
  TextBox1.Width = 540
  If TextBox1 = "Please type notes here" Then
    TextBox1 = ""
  End If
End Sub


Private Sub TextBox1_LostFocus()
  TextBox1.Height = TextBox1.Height
  TextBox1.Width = 540
  If TextBox1 = "" Then
    TextBox1 = "Please type notes here"
  End If
End Sub
I know that the code you provided would make it invisible but I only want it invisible if it contains "Please type notes here", meaning that it has not been typed in. Also, where would I put the code as I don't have any specific code that performs any printing action.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,738
Office Version
2013
Platform
Windows
Soo...
Before the print lines, use

Code:
If TextBox1 = "Please type notes here" Then
    TextBox1.visible=false
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,288
Which print lines?
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,738
Office Version
2013
Platform
Windows
Copy the lines I provided in post #4 , then insert them in the code that is doing the printing just before the code prints.
I'm assuming you are using code to do the printouts ??
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
1,288
But I can't add the code just before the code that does the printing as I don't do it from my form, I print from the excel program, meaning I can't modify the code. I also print to pdf instead of printing with a printer. Not sure if that makes a difference or not.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,738
Office Version
2013
Platform
Windows
Ok, maybe something like this then...in the "ThisWorkbook"

Code:
Sub Workbook_BeforePrint(Cancel As Boolean)
If TextBox1 = "Please type notes here" Then
    TextBox1.visible=false
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,095,225
Messages
5,443,197
Members
405,219
Latest member
CraneS

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top