|
|
|
|
|
|
Word
|
Delete Textbox if it contains a pre-defined word
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000
|
Submitted by:
|
lucas
|
Description:
|
If a textbox (from shape collection) in the document contains the word specified it is deleted when this macro is run.
|
Discussion:
|
You have instructions on a page for anyone opening the document. You wish to be able to remove the textbox with the instructions after they read them. (This sub only deals with a textbox of type "msoTextBox" from Shape collection)
|
Code:
|
instructions for use
|
Put this code In a standard module:
Option Explicit
Sub RemoveBoxIfItSaysInstructions()
Dim aShape As Shape
For Each aShape In ActiveDocument.Shapes
If aShape.Type = msoTextBox Then
If InStr(1, aShape.AlternativeText, "instructions", vbTextCompare) _
> 0 Then aShape.Delete
End If
Next
End Sub
|
How to use:
|
- Open the Visual Basic Editor by going to tools-Macro's-Visual Basic Editor or use Alt-F11
- On the toolbar of the Visual Basic Editor, go to insert - module
- In the module pane paste the code above.
- Close the Visual Basic Editor by clicking the X in the upper right corner or go to File-Close
|
Test the code:
|
- Put a textbox on your document and type the word Instructions(you can change this in the code)
- On the main menu go to tools-macro-macros.
- In the dialog window select RemoveBoxIfItSaysInstructions and then click run.
- Any textbox with the word instructions will be deleted.
|
Sample File:
|
Delete_textbox_if.zip 10.01KB
|
Approved by mdmackillop
|
This entry has been viewed 112 times.
|
|