Make text box invisible when print to pdf

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a textbox that has the text "Please type notes here" and a button that prints to pdf. If no notes are written in the textbox, a blank text box with the text "Please type notes here" will still appear when I print to pdf. How do I make the text box invisible if it contains the text "Please type notes here"?

This is my attempt
Code:
Sub NoText()
    With ThisWorkbook.Worksheets("NPSS_quote_sheet").Shapes("TestBox1")
        If .Value = "Please type notes here" Then
            .Visible = "false"
        End If
    End With
End Sub
 
Thanks Ken, got it to work with this code:

Code:
    If ThisWorkbook.Worksheets("NPSS_quote_sheet").TextBox1 = "Please type notes here" Then
        ThisWorkbook.Worksheets("NPSS_quote_sheet").TextBox1.Visible = False
    Call save_pdf
        ThisWorkbook.Worksheets("NPSS_quote_sheet").TextBox1.Visible = True
    End If
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Another way: try using PrintObject property & 'Sub TextBox1_Change' (or maybe 'Sub TextBox1_LostFocus'?), like this:

Code:
Private Sub TextBox1_Change()
  If TextBox1 = "Please type notes here" Then
    TextBox1.PrintObject = False
  Else
    TextBox1.PrintObject = True
  End If
End Sub
 
Last edited:
Upvote 0
I normally do as Akuini did in #12 but I disable printing the object by manually changing the Properties > PrintObject > False.

Here is a tweak for the ThisWorbook BeforeSave method.
Code:
Sub Workbook_BeforePrint(Cancel As Boolean)
    If Sheet1.TextBox1 = "Please type notes here" Then _
        Sheet1.TextBox1.Visible = False
    Application.OnTime Now, "ThisWorkbook.AfterSave"
End Sub

Private Sub AfterSave()
     Sheet1.TextBox1.Visible = True
End Sub
 
Last edited:
Upvote 0
What is the benefit of using this code over the code I got it to work with?
 
Upvote 0
It works for both the export to pdf (SaveAs) and normal printing. So, no matter what print method, and how it is done, manual or macro, it will do its thing.

Of course you can use the other method for the sheet's PrintOut (usual print method by code) as well. What you miss is explained above.
 
Last edited:
Upvote 0
I put the before print code in the thisworksheet object but where do I put
Private Sub AfterSave()?
 
Upvote 0
Code:
Sub Workbook_BeforePrint(Cancel As Boolean)
    If Sheet1.TextBox1 = "Please type notes here" Then _
        Sheet1.TextBox1.Visible = False
    Application.OnTime Now, "[COLOR="#FF0000"]ThisWorkbook[/COLOR].AfterSave"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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