S
Shell
Hi all,
I've been writing code in various environments, in varying
application, for a wide range of customers, for about 35 years now and
I'm still learning new stuff. This week I'm helping a friend
create a Word document template (Word 97) that stores a bunch of
answers to questions in the registry (Using SaveSetting and
GetSetting). In this document, as a part of the startup processing
(AutoNew), I want to load the stored values back into the bookmarked
places where they belong. The problem is I'm getting a error saying
the location is protected. From what I understand of this, yes it is!
I've protected the document so the body cannot be modified...but I
want to be able to enter text/values into those places where I've
defined fields (such as Textboxes, Checkboxes...et al)
Here's the code I have so far, the error comes from this line:
BkMrkRng.Text = RegVal
<code>
Option Explicit
Private BkMrk As Bookmark, BkMrkRng As Range
Sub AutoNew()
Dim sBMName As String, S1 As String, S2 As String, RegVal As String
For Each BkMrk In ActiveDocument.Bookmarks
sBMName = BkMrk.Name
S1 = Mid(sBMName, 1, Len(sBMName) - 1)
S2 = Mid(sBMName, Len(sBMName))
RegVal = GetSetting("MBD", S1, S2, vbNullString)
If RegVal <> vbNullString Then
Set BkMrkRng = ActiveDocument.Bookmarks(sBMName).Range
BkMrkRng.Text = RegVal
ActiveDocument.Bookmarks.Add sBMName, BkMrkRng
End If
Next BkMrk
End Sub
</code>
Hints: I've used the bookmark name, split into 2 strings, to name the
Section and Key for the SaveSetting function so I can easily retrieve
the values. I've learned that by setting the text value of a bookmark
it clears the bookmark itself, therefore making it necessary to Add
the bookmark back in after setting the text value.
Thanks for any help,
Shell (Yes, this is my real name)
I've been writing code in various environments, in varying
application, for a wide range of customers, for about 35 years now and
I'm still learning new stuff. This week I'm helping a friend
create a Word document template (Word 97) that stores a bunch of
answers to questions in the registry (Using SaveSetting and
GetSetting). In this document, as a part of the startup processing
(AutoNew), I want to load the stored values back into the bookmarked
places where they belong. The problem is I'm getting a error saying
the location is protected. From what I understand of this, yes it is!
I've protected the document so the body cannot be modified...but I
want to be able to enter text/values into those places where I've
defined fields (such as Textboxes, Checkboxes...et al)
Here's the code I have so far, the error comes from this line:
BkMrkRng.Text = RegVal
<code>
Option Explicit
Private BkMrk As Bookmark, BkMrkRng As Range
Sub AutoNew()
Dim sBMName As String, S1 As String, S2 As String, RegVal As String
For Each BkMrk In ActiveDocument.Bookmarks
sBMName = BkMrk.Name
S1 = Mid(sBMName, 1, Len(sBMName) - 1)
S2 = Mid(sBMName, Len(sBMName))
RegVal = GetSetting("MBD", S1, S2, vbNullString)
If RegVal <> vbNullString Then
Set BkMrkRng = ActiveDocument.Bookmarks(sBMName).Range
BkMrkRng.Text = RegVal
ActiveDocument.Bookmarks.Add sBMName, BkMrkRng
End If
Next BkMrk
End Sub
</code>
Hints: I've used the bookmark name, split into 2 strings, to name the
Section and Key for the SaveSetting function so I can easily retrieve
the values. I've learned that by setting the text value of a bookmark
it clears the bookmark itself, therefore making it necessary to Add
the bookmark back in after setting the text value.
Thanks for any help,
Shell (Yes, this is my real name)