+ Reply to Thread
Results 1 to 2 of 2

Thread: Clear all TextBoxes in a document

  1. #1
    Forum Contributor
    Join Date
    12-13-2007
    Location
    Central New York
    Posts
    130

    Clear all TextBoxes in a document

    Hello,

    I have a several textboxes in a Word 2010 document to creat a form. I am trying to find a way to clear all of them when someone wants to start over with a new entry. I already know about the resetting of protection to reset formfields, but my boss wants to use the regular text boxes. Also, I understand about using a template and how opening the template will reset the boxes when opened but I want users to be able to reset it without closing/reopening.

    I can get it to work if I do each one individually, but I would rather do some code similar to the code below in case my boss adds more boxes.

    The code below works great for UserForms but it does not work for the controls in the document itself.

    Any help would be appreciated.

    Thanks

    Mark

    For Each Control In Me.Controls 'Clear Input Boxes
        If TypeOf Control Is MSForms.TextBox Then
           Control.Text = ""
        End If
        If TypeOf Control Is MSForms.ComboBox Then
           Control.Text = ""
           Control.Clear
        End If
        If TypeOf Control Is MSForms.CheckBox Then
           Control.Value = False
           Control.Caption = ""
           Control.Visible = False
        End If
    Next

  2. #2
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Clear all TextBoxes in a document

    It depends whether the textboxes are inlineshapes or shapes:

     
    Sub snb()
      For Each tb In ThisDocument.InlineShapes
        If tb.Type = 5 Then tb.OLEFormat.Object.Text = ""
      Next
    end sub
    if necessary change inlineshapes to shapes.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0