Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.pagelayout
|
|||
|
|||
Open with Cursor at bookmark in Header
I created a template in Word in which the user must enter his/her name in the
header. I would like for the document to open with the cursor in this spot within the header. I created a bookmark in the header. How can I set it so that when the document is created from the template, that the cursor immediately goes to the bookmark in the header? |
#2
Posted to microsoft.public.word.pagelayout
|
|||
|
|||
Open with Cursor at bookmark in Header
In the template, you could save a macro named AutoNew and let the macro
display the header with the bookmark selected. However, I suggest another approach that automatically inserts the user name. This requires that you can rely on the name defined in Tools Options User Information tab being correct. You could then insert the AutoNew macro below in the template - the macro will run when a new document is created, based on that template. In the macro, change "UserName" to the name of your bookmark - the macro will automatically update the bookmark with the currently defined user name: Sub AutoNew() Dim oRange As Range Dim strBkmName As String strBkmName = "UserName" 'To prevent error if bookmark is missing, check first If ActiveDocument.Bookmarks.Exists(strBkmName) Then Set oRange = ActiveDocument.Bookmarks(strBkmName).Range 'Insert the user name oRange.Text = Application.UserName 'The bookmark is gone - recreate it ActiveDocument.Bookmarks.Add strBkmName, oRange Else 'What to do if the bookmark was not in the template? 'Insert code here End If 'Clean up Set oRange = Nothing End Sub If you cannot rely on the defined user name, you could change the macro so that it displays an inputbox, asking about the user name. Please post back in case you need an inputbox and need help on the VBA code. For help on installing a macro, see: http://www.gmayor.com/installing_macro.htm -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "ItsBarbara" wrote: I created a template in Word in which the user must enter his/her name in the header. I would like for the document to open with the cursor in this spot within the header. I created a bookmark in the header. How can I set it so that when the document is created from the template, that the cursor immediately goes to the bookmark in the header? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Go to bookmark in Header on Open | Microsoft Word Help | |||
New documents open with cursor above header, how to fix? | Microsoft Word Help | |||
All my new documents open with the cursor at the header location. | Page Layout | |||
Can I get the cursor to goto a bookmark on opening | New Users | |||
Header and Bookmark | New Users |