Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Make text box invisible when print to pdf
Thanks Thanks: 0 Likes Likes: 0

  1. #11
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    935
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    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

  2. #12
    Board Regular Akuini's Avatar
    Join Date
    Feb 2016
    Location
    Indonesia
    Posts
    2,050
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    4 Thread(s)

    Default Re: Make text box invisible when print to pdf

    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 by Akuini; Sep 5th, 2019 at 10:17 PM.

  3. #13
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,050
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    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 by Kenneth Hobson; Sep 5th, 2019 at 10:34 PM.

  4. #14
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    935
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    What is the benefit of using this code over the code I got it to work with?

  5. #15
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,050
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    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 by Kenneth Hobson; Sep 5th, 2019 at 11:44 PM.

  6. #16
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    935
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    I put the before print code in the thisworksheet object but where do I put
    Private Sub AfterSave()?

  7. #17
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,050
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Make text box invisible when print to pdf

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •