View Full Version : [SOLVED:] Macro to remove bookmarks in legacy form objects
JohnSW
05-15-2017, 01:29 PM
Want to be able to delete bookmarks from legacy form fields in a selected range. Have the following macros that delete entry and exit macros but fails on the name line.
Sub DeleteSelectedFFMacros()
Dim FF as FormField
For Each FF In Selection.Range.FormFields
FF.ExitMacro = ""
FF.EntryMacro = ""
FF.Name= ""
Next FF
End Sub
Also tried the following on just the bookmarks but it does work for form fields.
Sub DeleteSelectedBMs()
Dim BM as Bookmark
For Each BM In Selection.Range.Bookmarks
BM.Delete
Next BM
End Sub
gmaxey
05-15-2017, 01:58 PM
Sub DeleteSelectedFFMacros()
Dim FF As FormField
For Each FF In Selection.Range.FormFields
FF.ExitMacro = ""
FF.EntryMacro = ""
FF.Range.Bookmarks(1).Delete
Next FF
End Sub
gmaxey
05-15-2017, 01:59 PM
Btw, your second macro seems to work equally well.
JohnSW
05-15-2017, 04:10 PM
Btw, your second macro seems to work equally well.
Thanks Greg.
The macros sort of work for me. The remove the bookmarks visually from the screen and from the list of bookmarks. On opening the form field options dialog though, the bookmark name still appears. If you rerun the macro, it will throw an error apparently trying to delete a bookmark it cannot find. Any ideas on why the bookmarks names ghost and how to remove them?
Also, the macro would throw an error on form fields with no bookmark. I added an "If not FF.Name = "" Then" before the bookmark deletion code which seems to fix that.
gmaxey
05-15-2017, 06:04 PM
I don't think it is the bookmark name that is a ghost. The bookmark is gone, but when you reopen the dialog Word automatically assigns a bookmark that matches the formfield name. Formfields can't be named "" or be duplicated.
What are you really trying to do?
gmaxey
05-15-2017, 06:21 PM
I am apparently mistaken above. Through and convoluted manual process you can create a formfield that is not bookmarked with a name = ""
Insert a formfield.
Select and copy it
Paste to a new location
The pasted FF is not bookmarked
Open the dialog. The paste FF is not named.
Delete the original FF
Not sure this could be done via VBA.
JohnSW
05-16-2017, 09:00 AM
Greg, thanks for your help. It turns out the 2nd macro in my original post serve my purposes. That the bookmark name is remembered somehow and pops up if you go to the form field option isn't important. We have a macro that takes a group of selected checkboxes and by creating custom bookmarks, and entry and exit macros, makes the checkboxes mutually exclusive. That macro would fail if a checkbox already had a custom bookmark name. The new macro fixes that.
We have used a macro for years that deletes all generic form field bookmarks or so we thought. It removed the bookmark from the bookmarks list and from appearing as a bookmark on screen as we only want to see custom bookmarks as they are connected to macros or other fields. I didn't realize that if you go back into the form field options for the object with the VBA "removed" bookmark, the original bookmark name would reappear. I did know that manually removing a bookmark name leave an empty bookmark, or copying an pasting an form object, would leave an empty bookmark in the new object. Without paying attention, I just assumed out macro did the same thing.
macropod
05-16-2017, 05:55 PM
If you wanted to delete all bookmarks, you could, of course, use:
With ActiveDocument
.Bookmarks.ShowHidden = True
While .Bookmarks.Count > 0
.Bookmarks(1).Delete
Wend
End With
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.