P
PumaMan
I have a word doc that is pulled up from a template in VBA. I have tried to
protect the doc after it opens & sends the data from excel to the appropriate
bookmarks. I just need to protect the doc for filling in forms only at that
point, but can't get it to work. I've followed the instructions of earlier
posts i've found here and checked the Word MVP site, nothing works.
Something must be wrong with my code...
The code to protect is towards the bottom. Thank you in advance!
Sub WriteToWordDoc()
Dim WordObject As Object 'Word Object
Dim SigCardTemplateString As String 'Template name
Dim SigCardPathString As String 'Path & Template
If AccountState = "FLORIDA" Then
SigCardTemplateString = "FL W9 Sig.dot"
SigCardPathString = "C:\Documents and Settings\nbk337h\Desktop\" & _
"Excel Process Docs\" & SigCardTemplateString
End If
Set WordObject = CreateObject("Word.Application")
With WordObject
'Create a new Word document based on the template
.Documents.Add Template:=SigCardPathString
.Visible = True 'Can be False
.ActiveDocument.Bookmarks("AccountNumberBookmark").Range =
AccountNumber
.ActiveDocument.Bookmarks("AccountTypeBookmark").Range = AccountType
.ActiveDocument.Bookmarks("CaseNumber").Range = CaseNumber
.ActiveDocument.Bookmarks("TitleLine1Bookmark").Range = TitleLine1
.ActiveDocument.Bookmarks("TitleLine2Bookmark").Range = TitleLine2
.ActiveDocument.Bookmarks("TitleLine3Bookmark").Range = TitleLine3
.ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="123"
End With
'Cleanup
Set WordObject = Nothing
End Sub
protect the doc after it opens & sends the data from excel to the appropriate
bookmarks. I just need to protect the doc for filling in forms only at that
point, but can't get it to work. I've followed the instructions of earlier
posts i've found here and checked the Word MVP site, nothing works.
Something must be wrong with my code...
The code to protect is towards the bottom. Thank you in advance!
Sub WriteToWordDoc()
Dim WordObject As Object 'Word Object
Dim SigCardTemplateString As String 'Template name
Dim SigCardPathString As String 'Path & Template
If AccountState = "FLORIDA" Then
SigCardTemplateString = "FL W9 Sig.dot"
SigCardPathString = "C:\Documents and Settings\nbk337h\Desktop\" & _
"Excel Process Docs\" & SigCardTemplateString
End If
Set WordObject = CreateObject("Word.Application")
With WordObject
'Create a new Word document based on the template
.Documents.Add Template:=SigCardPathString
.Visible = True 'Can be False
.ActiveDocument.Bookmarks("AccountNumberBookmark").Range =
AccountNumber
.ActiveDocument.Bookmarks("AccountTypeBookmark").Range = AccountType
.ActiveDocument.Bookmarks("CaseNumber").Range = CaseNumber
.ActiveDocument.Bookmarks("TitleLine1Bookmark").Range = TitleLine1
.ActiveDocument.Bookmarks("TitleLine2Bookmark").Range = TitleLine2
.ActiveDocument.Bookmarks("TitleLine3Bookmark").Range = TitleLine3
.ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="123"
End With
'Cleanup
Set WordObject = Nothing
End Sub