![]() |
|
#1
|
||||
|
||||
![]()
The following will put the bookmark in the main header of the first section after the third character if there is one. (If you want it to start from page 2, then you will either need a section break and make it Sections(2) or have a different first page header.
Code:
Sub addBM_Header() Dim oRng As Range Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range If Len(oRng) > 3 Then oRng.Start = oRng.Start + 3 oRng.Collapse 1 End If ActiveDocument.Bookmarks.Add Range:=oRng, Name:="NombreEncab" End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#2
|
|||
|
|||
![]()
Greetings, thanks for the solution you give me, and it works perfect, but I was inconvenienced that when I assign the text to the bookmark, it is added more and more, therefore I have seen the need for the document to close delete the bookmark so that when the document is opened again it is created and the text is assigned that works but is added. In other words, the Bookmark is deleted but the text is not deleted. Then the other way would be to search for the text and replace with nothing ""
But the macro does not work. Well, I think this is another issue. Practically with that I would have the document finished, I would prefer to send it so you can take a look and give me the definitive help. As they say, I'm having the wonderful thing. HTML Code:
Sub eliminarMiBM() ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader ' ActiveDocument.Sections(1).headers (wdHeaderFooterPrimary) If ActiveDocument.Bookmarks.Exists("NombreEncab") = True Then ActiveDocument.Bookmarks("NombreEncab").Delete End If ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 'If ActiveDocument.Bookmarks.Exists("NombreEncab") = True Then ' 'ActiveDocument.Bookmarks("NombreEncab").Select ' ActiveDocument.Bookmarks("NombreEncab").Delete ' End If End Sub HTML Code:
Sub DelTexHeader() ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'ActiveDocument.Sections(1).headers(wdHeaderFooterPrimary).Range 'ActiveWindow.ActivePane.View.NextHeaderFooter ActiveDocument.Find.ClearFormatting ActiveDocument.Find.Replacement.ClearFormatting With ActiveDocument.Find .Text = "Name Here" .Replacement.Text = "" End With 'Selection.Find.Execute ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument End Sub |
![]() |
Tags |
vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Different Odd/Even Header with no header on first page of new chapters | bbecker24 | Word | 4 | 05-09-2018 08:17 PM |
Header Info: Connecting seclected items for 1st page Header into Following Pages | SMHa | Word | 1 | 08-24-2016 10:00 AM |
No Header | bullsfan586 | Word | 1 | 08-29-2015 07:55 PM |
How do I get this header? | veed | Word | 7 | 04-10-2013 12:25 AM |
How to get this header? | msvis | Word | 1 | 12-04-2011 07:45 PM |