Hi,
I've created a template in Word 2003. I have a Header that I would like to display a title in. However, rather than having the user have to open up the header and change the title, I would like to simply prompt the user to enter one whenever they create a new doc off of the template.
I found thread68-830116 that supplied a link to one way to do this. It had me set bookmarks, then enter the code below in VBA.
When creating a new doc from the template, the prompt appears and allows me to enter a title. However, upon pressing OK, the prompt disappears and I am left with a blank doc. My header does not exist on this doc for some reason and therefore the title does not appear.
As a note, the bmkTitle bookmark is located in the header and the bmkStartHere bookmark is located on the first line of the document.
Any ideas on why after I enter the title in my little form and press OK, the blank document that appears does not include my header?
Thanks for any assistance!
Private Sub Document_New()
Dim oForm As frmTitle
On Error GoTo Error_DocumentNew
Set oForm = New frmTitle
oForm.Tag = "Cancel"
oForm.Show
If oForm.Tag = "OK" Then
'ActiveDocument.Bookmarks("bmkTitle").Range.Text = oForm.txtTitle.Text
'ActiveDocument.Bookmarks("bmkStartHere").Range.Select
Unload oForm
Set oForm = Nothing
Else
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
End If
Exit_DocumentNew:
Exit Sub
Error_DocumentNew:
On Error Resume Next
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
Resume Exit_DocumentNew
End Sub
I've created a template in Word 2003. I have a Header that I would like to display a title in. However, rather than having the user have to open up the header and change the title, I would like to simply prompt the user to enter one whenever they create a new doc off of the template.
I found thread68-830116 that supplied a link to one way to do this. It had me set bookmarks, then enter the code below in VBA.
When creating a new doc from the template, the prompt appears and allows me to enter a title. However, upon pressing OK, the prompt disappears and I am left with a blank doc. My header does not exist on this doc for some reason and therefore the title does not appear.
As a note, the bmkTitle bookmark is located in the header and the bmkStartHere bookmark is located on the first line of the document.
Any ideas on why after I enter the title in my little form and press OK, the blank document that appears does not include my header?
Thanks for any assistance!
Private Sub Document_New()
Dim oForm As frmTitle
On Error GoTo Error_DocumentNew
Set oForm = New frmTitle
oForm.Tag = "Cancel"
oForm.Show
If oForm.Tag = "OK" Then
'ActiveDocument.Bookmarks("bmkTitle").Range.Text = oForm.txtTitle.Text
'ActiveDocument.Bookmarks("bmkStartHere").Range.Select
Unload oForm
Set oForm = Nothing
Else
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
End If
Exit_DocumentNew:
Exit Sub
Error_DocumentNew:
On Error Resume Next
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
Resume Exit_DocumentNew
End Sub