Macro to delete empty bookmarks and space it occupies.

D

durmalbs

I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
 
M

macropod

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.
 
D

durmalbs

This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

macropod said:
Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.
 
M

macropod

Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

macropod said:
Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.
 
D

durmalbs

Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

macropod said:
Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.

.
 
M

macropod

Hi durmalbs,

That code doesn't update the bookmarks - it inserts text next to them. Since it seems you're updating numerous bookmarks, try:

Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub

which you can call from your command buttons like:

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookmark("TextSleeve", "Packer Setting")
End If
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.

.
 
D

durmalbs

I read your last post about it putting text beside instead of updating the
bookmark.
I appreciate your help alot, but I am not really understanding the
code(nothing new). But if I want to update the bookmark with the appropriate
text how would I load this do i need to change the reference in the below sub
to anything

The bookmark is "TextSleeve" and the text to insert is "Packer Setting"
would these be entered below where you show BmkNm and NewTxt.

Sorry for the stupidity

Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub


which you can call from your command buttons like:


Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookmark("TextSleeve", "Packer Setting")
End If
End Sub





durmalbs said:
Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.

.
 
M

macropod

Hi durmalbs,

Simple: Delete your existing CommandButton1_Click sub and replace it with the one I posted, plus the UpdateBookmark sub.

If, as I understand it, you have other subs like your CommandButton1_Click sub, simply modify them along the lines of the changes I
made to your CommandButton1_Click sub.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I read your last post about it putting text beside instead of updating the
bookmark.
I appreciate your help alot, but I am not really understanding the
code(nothing new). But if I want to update the bookmark with the appropriate
text how would I load this do i need to change the reference in the below sub
to anything

The bookmark is "TextSleeve" and the text to insert is "Packer Setting"
would these be entered below where you show BmkNm and NewTxt.

Sorry for the stupidity

Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub


which you can call from your command buttons like:


Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookmark("TextSleeve", "Packer Setting")
End If
End Sub





durmalbs said:
Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.


.
 
D

durmalbs

I must not be loading right here is what I installed and now when I hit the
command button after choosing my option in cboSleeve it input s nothing, here
is how I loaded the macro. I 'm sure I've done something wrong with how I
loaded it or loaded in the wrong place.

Sub UpdateBookMark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
Set BmkRng = .Bookmarks(BmkNm).Range
BmkRng.Text = NeTxt
..Bookmarks.Add BmkNm, BmkRng
End If
End With
Set NmkRng = Nothing
End Sub



Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookMark("TextSLEEVE", "Packer Setting")
End If
End Sub



macropod said:
Hi durmalbs,

Simple: Delete your existing CommandButton1_Click sub and replace it with the one I posted, plus the UpdateBookmark sub.

If, as I understand it, you have other subs like your CommandButton1_Click sub, simply modify them along the lines of the changes I
made to your CommandButton1_Click sub.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I read your last post about it putting text beside instead of updating the
bookmark.
I appreciate your help alot, but I am not really understanding the
code(nothing new). But if I want to update the bookmark with the appropriate
text how would I load this do i need to change the reference in the below sub
to anything

The bookmark is "TextSleeve" and the text to insert is "Packer Setting"
would these be entered below where you show BmkNm and NewTxt.

Sorry for the stupidity

Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub


which you can call from your command buttons like:


Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookmark("TextSleeve", "Packer Setting")
End If
End Sub





durmalbs said:
Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


:

Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.


.

.
 
M

macropod

Hi durmalbs,

I suspect you haven't got 'Option Explicit' set, as there's a typo in your rendition of the UpdateBookMark sub.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I must not be loading right here is what I installed and now when I hit the
command button after choosing my option in cboSleeve it input s nothing, here
is how I loaded the macro. I 'm sure I've done something wrong with how I
loaded it or loaded in the wrong place.

Sub UpdateBookMark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
Set BmkRng = .Bookmarks(BmkNm).Range
BmkRng.Text = NeTxt
.Bookmarks.Add BmkNm, BmkRng
End If
End With
Set NmkRng = Nothing
End Sub



Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookMark("TextSLEEVE", "Packer Setting")
End If
End Sub



macropod said:
Hi durmalbs,

Simple: Delete your existing CommandButton1_Click sub and replace it with the one I posted, plus the UpdateBookmark sub.

If, as I understand it, you have other subs like your CommandButton1_Click sub, simply modify them along the lines of the changes
I
made to your CommandButton1_Click sub.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I read your last post about it putting text beside instead of updating the
bookmark.
I appreciate your help alot, but I am not really understanding the
code(nothing new). But if I want to update the bookmark with the appropriate
text how would I load this do i need to change the reference in the below sub
to anything

The bookmark is "TextSleeve" and the text to insert is "Packer Setting"
would these be entered below where you show BmkNm and NewTxt.

Sorry for the stupidity

Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
With ActiveDocument
If.Bookmarks.Exists(BmkNm) Then
Set BmkRng =.Bookmarks(BmkNm).Range
BmkRng.Text = NewTxt
.Bookmarks.Add BmkNm, BmkRng
End if
End With
Set BmkRng = Nothing
End Sub


which you can call from your command buttons like:


Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
Call UpdateBookmark("TextSleeve", "Packer Setting")
End If
End Sub





:

Here is an example of how the bookmark is populated by the command button
from info entered in Combo Box "Sleeve". The bookmark is named "TextSleeve",
is this not correct?

Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub


:

Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.


.

.
 
D

durmalbs

I finally got the Subs to work I really appreciate it. Now another question
is there a way to tell it to not remove certain bookmarks?

macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

macropod said:
Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.

.
 
M

macropod

Hi durmalbs,

Sure, just modify the code at:
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
to test against the relevant set of bookmark names. For a single bookmark name, you might use:
If .Bookmarks(oBkMk).Empty = True Then _
If .Bookmarks(oBkMk).Name <> "MyName" Then oBkMk.Range.Paragraphs(1).Range.Delete
For multiple bookmarks, I'd be inclined to create another string variable, insert the list in comma-separated format then, after the
'Empty' test, use a loop in conjunction with Split to check though the list entries. If not found in the list, then delete. There's
plenty of code snippets about to show you how to do that.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
I finally got the Subs to work I really appreciate it. Now another question
is there a way to tell it to not remove certain bookmarks?

macropod said:
Hi durmalbs,

The problem is that whatever your code does, it doesn't populate the bookmarks. As requested, though, the macro deletes the
paragraphs containing empty bookmarks. You have two choices:
1. populate the bookmarks correctly; or
2. modify the macro to delete empty paragrahs containing bookmarks.

--
Cheers
macropod
[Microsoft MVP - Word]


durmalbs said:
This deletes the bookmarks,but it does all of them. When I hit my command
button it inserts the text into the appropriate bookmark, then there are some
bookmarks left I need to be able to delete those left. When I insert this
then pick my combo box choices the hit my command button to run it adds the
text to the appropriate bookmark, but when I then run this Sub it removes the
bookmarks where the text was inserted along with the blanks.

Any suggestions?

:

Hi durmalbs,

Try:
Sub KillEmptyBkMrkParas()
Dim oBkMk As Bookmark, bBkState As Boolean
With ActiveDocument
bBkState = .Bookmarks.ShowHidden
.Bookmarks.ShowHidden = False
For Each oBkMk In .Bookmarks
If .Bookmarks(oBkMk).Empty = True Then oBkMk.Range.Paragraphs(1).Range.Delete
Next
.Bookmarks.ShowHidden = bBkState
End With
End Sub

Note: I've taken your reference to 'blank bookmarks' to mean they're empty.

--
Cheers
macropod
[Microsoft MVP - Word]


I have a document that once I run the macro to insert text from combo box
choices it still has some blank bookmarks that I would like to have a macro
to delete the bookmarks and the line that was marked ( hope this is not
confusing).
so the document looks like this,

3.42 run packer
3.43 (Bookmark "TextP1")
3.44 Set packer

So I need the macro to delete the whole line 3.43 and move 3.44 up.

Any help would be appreciated I am very new to macros so be gentle if
possible.
.

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top