J
jab
Hi
I have created a userform that bring up the content from certain
bookmarks in the document and presents them in the fields of the form.
The user changes these settings and the new content of the bookmarks
are cascaded throughout the documents headers and footers (and in text)
via ref fields.
The bookmarks themselves is hidden in the header of the first page of
the document in a textbox that is hidden behind some header graphics.
This to make it as hard as possible to accidentally delete them.
Everything works fine but if the bookmarks despite these efforts have
been deleted by the users, we get a "5941" runtime error.
Can someone please help me write code that checks if the bookmarks are
still there, if there not (any of them) recreates them in the same
fashion / or a better fashion?
NOTE the current bookmarks of the templates can right now not be
reached via Edit/goto bookmarks. One needs first to go into the headers
of the docs and into a textbox within them to be able to reach them via
that command in word. Here is the code for the form/bookmark:
Option Explicit
Private Sub UserForm_Initialize()
Dim project As String
Dim Clientname As String
Dim DocumentType As String
Dim Author As String
Dim prefdate As String
project = ActiveDocument.Bookmarks("Project").Range.Text
TxtProject.Text = project
Clientname = ActiveDocument.Bookmarks("clientname").Range.Text
TxtClient.Text = Clientname
DocumentType = ActiveDocument.Bookmarks("documenttype").Range.Text
TxtDocumentType.Text = DocumentType
Author = ActiveDocument.Bookmarks("author").Range.Text
txtAuthor.Text = Author
prefdate = ActiveDocument.Bookmarks("prefdate").Range.Text
Txtprefdate.Text = prefdate
End Sub
Private Sub cmdCancel_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="goback"
FrmDocProp.Hide
Unload FrmDocProp
Exit Sub
End Sub
Private Sub CmdOK_Click()
Dim vProject As String
Dim vClient As String
Dim vDocType As String
Dim vAuthor As String
Dim vprefdate As String
vProject = FrmDocProp.TxtProject.Text
vClient = FrmDocProp.TxtClient.Text
vDocType = FrmDocProp.TxtDocumentType.Text
vAuthor = FrmDocProp.txtAuthor.Text
vprefdate = FrmDocProp.Txtprefdate.Text
'declare a range
Dim bkProjectRange As Range
Dim bkClientRange As Range
Dim bkDocTypeRange As Range
Dim bkAuthorRange As Range
Dim bkPrefdateRange As Range
'set the range equal to your current bookmark
Set bkClientRange = ActiveDocument.Bookmarks("Clientname").Range
Set bkProjectRange = ActiveDocument.Bookmarks("Project").Range
Set bkDocTypeRange = ActiveDocument.Bookmarks("DocumentType").Range
Set bkAuthorRange = ActiveDocument.Bookmarks("Author").Range
Set bkPrefdateRange = ActiveDocument.Bookmarks("Prefdate").Range
'pass in the info now contained in the variable (what the user
typed)
bkProjectRange.Text = vProject
bkClientRange.Text = vClient
bkDocTypeRange.Text = vDocType
bkAuthorRange.Text = vAuthor
bkPrefdateRange.Text = vprefdate
'wrap the same bookmark around this text
ActiveDocument.Bookmarks.Add "ClientName", bkClientRange
ActiveDocument.Bookmarks.Add "Project", bkProjectRange
ActiveDocument.Bookmarks.Add "DocumentType", bkDocTypeRange
ActiveDocument.Bookmarks.Add "Author", bkAuthorRange
ActiveDocument.Bookmarks.Add "Prefdate", bkPrefdateRange
I have created a userform that bring up the content from certain
bookmarks in the document and presents them in the fields of the form.
The user changes these settings and the new content of the bookmarks
are cascaded throughout the documents headers and footers (and in text)
via ref fields.
The bookmarks themselves is hidden in the header of the first page of
the document in a textbox that is hidden behind some header graphics.
This to make it as hard as possible to accidentally delete them.
Everything works fine but if the bookmarks despite these efforts have
been deleted by the users, we get a "5941" runtime error.
Can someone please help me write code that checks if the bookmarks are
still there, if there not (any of them) recreates them in the same
fashion / or a better fashion?
NOTE the current bookmarks of the templates can right now not be
reached via Edit/goto bookmarks. One needs first to go into the headers
of the docs and into a textbox within them to be able to reach them via
that command in word. Here is the code for the form/bookmark:
Option Explicit
Private Sub UserForm_Initialize()
Dim project As String
Dim Clientname As String
Dim DocumentType As String
Dim Author As String
Dim prefdate As String
project = ActiveDocument.Bookmarks("Project").Range.Text
TxtProject.Text = project
Clientname = ActiveDocument.Bookmarks("clientname").Range.Text
TxtClient.Text = Clientname
DocumentType = ActiveDocument.Bookmarks("documenttype").Range.Text
TxtDocumentType.Text = DocumentType
Author = ActiveDocument.Bookmarks("author").Range.Text
txtAuthor.Text = Author
prefdate = ActiveDocument.Bookmarks("prefdate").Range.Text
Txtprefdate.Text = prefdate
End Sub
Private Sub cmdCancel_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="goback"
FrmDocProp.Hide
Unload FrmDocProp
Exit Sub
End Sub
Private Sub CmdOK_Click()
Dim vProject As String
Dim vClient As String
Dim vDocType As String
Dim vAuthor As String
Dim vprefdate As String
vProject = FrmDocProp.TxtProject.Text
vClient = FrmDocProp.TxtClient.Text
vDocType = FrmDocProp.TxtDocumentType.Text
vAuthor = FrmDocProp.txtAuthor.Text
vprefdate = FrmDocProp.Txtprefdate.Text
'declare a range
Dim bkProjectRange As Range
Dim bkClientRange As Range
Dim bkDocTypeRange As Range
Dim bkAuthorRange As Range
Dim bkPrefdateRange As Range
'set the range equal to your current bookmark
Set bkClientRange = ActiveDocument.Bookmarks("Clientname").Range
Set bkProjectRange = ActiveDocument.Bookmarks("Project").Range
Set bkDocTypeRange = ActiveDocument.Bookmarks("DocumentType").Range
Set bkAuthorRange = ActiveDocument.Bookmarks("Author").Range
Set bkPrefdateRange = ActiveDocument.Bookmarks("Prefdate").Range
'pass in the info now contained in the variable (what the user
typed)
bkProjectRange.Text = vProject
bkClientRange.Text = vClient
bkDocTypeRange.Text = vDocType
bkAuthorRange.Text = vAuthor
bkPrefdateRange.Text = vprefdate
'wrap the same bookmark around this text
ActiveDocument.Bookmarks.Add "ClientName", bkClientRange
ActiveDocument.Bookmarks.Add "Project", bkProjectRange
ActiveDocument.Bookmarks.Add "DocumentType", bkDocTypeRange
ActiveDocument.Bookmarks.Add "Author", bkAuthorRange
ActiveDocument.Bookmarks.Add "Prefdate", bkPrefdateRange