Need text box to be invisible when printing

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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"?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Use
Code:
textboxname.visible=false
and put it just before the print lines of code
 
Upvote 0
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.
 
Upvote 0
Soo...
Before the print lines, use

Code:
If TextBox1 = "Please type notes here" Then
    TextBox1.visible=false
 
Upvote 0
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 ??
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top