Results 1 to 8 of 8

Thread: Need text box to be invisible when printing
Thanks Thanks: 0 Likes Likes: 0

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

    Default Need text box to be invisible when printing

    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"?

  2. #2
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,806
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Need text box to be invisible when printing

    Use
    Code:
    textboxname.visible=false
    and put it just before the print lines of code
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

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

    Default Re: Need text box to be invisible when printing

    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.

  4. #4
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,806
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Need text box to be invisible when printing

    Soo...
    Before the print lines, use

    Code:
    If TextBox1 = "Please type notes here" Then
        TextBox1.visible=false
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

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

    Default Re: Need text box to be invisible when printing

    Which print lines?

  6. #6
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,806
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Need text box to be invisible when printing

    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 ??
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

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

    Default Re: Need text box to be invisible when printing

    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.

  8. #8
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    South Western NSW
    Posts
    17,806
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Need text box to be invisible when printing

    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
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

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
  •