Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2019, 08:08 PM
gmayor's Avatar
gmayor gmayor is offline Add bookmark with vba in the header Windows 10 Add bookmark with vba in the header Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #2  
Old 08-18-2019, 07:09 PM
Visor Visor is offline Add bookmark with vba in the header Windows 10 Add bookmark with vba in the header Office 2013
Advanced Beginner
Add bookmark with vba in the header
 
Join Date: Aug 2019
Posts: 38
Visor is on a distinguished road
Default

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
If you approve that I send you the complete document, I would like you to tell me.
Reply With Quote
Reply

Tags
vba



Similar Threads
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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft