Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2015, 09:38 AM
ChrisDevrell ChrisDevrell is offline Add a bookmark to the Header using Word VBA Windows 7 32bit Add a bookmark to the Header using Word VBA Office 2010 32bit
Novice
Add a bookmark to the Header using Word VBA
 
Join Date: May 2012
Location: Southampton
Posts: 3
ChrisDevrell is on a distinguished road
Default Add a bookmark to the Header using Word VBA

Its easy to add a bookmark to the header where there is a range to add it to, eg:



ActiveDocument.Bookmarks.Add name:="MyBookmark", Range:=ActiveDocument.Sections(1).Headers(wdHeader FooterPrimary).range.Paragraphs(1).Range


But how do you set the bookmark to be at the beginning of the header with no range enclosed, ie just the I-beam shape I where the bookmark does not enclose anything.

Can this be done without using the selection object?

It sounds easy but I dont see a way to do it.

Any ideas?

Thanks
Chris
Reply With Quote
  #2  
Old 02-06-2015, 01:24 PM
macropod's Avatar
macropod macropod is offline Add a bookmark to the Header using Word VBA Windows 7 64bit Add a bookmark to the Header using Word VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Dim Rng As Range
With ActiveDocument
  Set Rng = .Sections(1).Headers(wdHeaderFooterPrimary).Range
  Rng.Collapse wdCollapseStart
  .Bookmarks.Add Name:="MyBookmark", Range:=Rng
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-06-2015, 04:15 PM
ChrisDevrell ChrisDevrell is offline Add a bookmark to the Header using Word VBA Windows 7 32bit Add a bookmark to the Header using Word VBA Office 2010 32bit
Novice
Add a bookmark to the Header using Word VBA
 
Join Date: May 2012
Location: Southampton
Posts: 3
ChrisDevrell is on a distinguished road
Default

Thanks Paul

That works a treat.

Inserting a bookmark was a general idea and I wanted to make it work for inserting autotext without damaging the header and your code works the same there:

Dim Rng As Range
Set Rng = ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary).Range
Rng.Collapse wdCollapseStart
ThisDocument.AttachedTemplate.AutoTextEntries("_Cl assificationStatus").Insert RichText:=True, where:=Rng

Thanks again
Chris.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a bookmark to the Header using Word VBA Moving Selected Items from a Multiselect Listbox on a userform to a bookmark in Word marksm33 Word VBA 3 01-15-2015 07:55 PM
Add a bookmark to the Header using Word VBA Getting mult resps. selected in listbox to concatenate & paste at a bookmark in Word marksm33 Word VBA 3 01-15-2015 05:59 PM
Adding field in word in header in a bookmark in table with Excel vba Late Binding Hdr Excel Programming 6 02-11-2013 02:58 AM
Add a bookmark to the Header using Word VBA Open header to insert text into bookmark Amapola188 Word VBA 3 07-12-2012 05:16 PM
Add a bookmark to the Header using Word VBA [Word 2007] How to hyperlink directly another word file chapter/paragraph/bookmark? LeeFX Word 4 05-05-2011 05:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:08 PM.


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