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.
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" <durm...@discussions.microsoft.com> wrote in message news:6D44034D-3E64-463B...@microsoft.com...
Any suggestions?
"macropod" wrote:
> .
>
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" <durm...@discussions.microsoft.com> wrote in message news:E15A24DD-28D9-4822...@microsoft.com...
Private Sub CommandButton1_Click()
If cboSleeve > "0" Then
ActiveDocument.Bookmarks("TextSleeve").Select
Selection.TypeText Text:="Packer Setting"
End If
End Sub
"macropod" wrote:
> .
>
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" <durm...@discussions.microsoft.com> wrote in message news:45FADDC1-1650-4973...@microsoft.com...
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
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" <durm...@discussions.microsoft.com> wrote in message news:EA43FC85-9C89-4303...@microsoft.com...
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" wrote:
> .
>
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" <durm...@discussions.microsoft.com> wrote in message news:DB6D1B2D-FCCB-4DEC...@microsoft.com...
"macropod" wrote:
> .
>
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" <durm...@discussions.microsoft.com> wrote in message news:6E43EDAB-CA12-422F...@microsoft.com...