Thread: [Solved] Text Form Field & REF Field
View Single Post
 
Old 08-09-2017, 07:20 PM
cltay87 cltay87 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default

Hi Macropod, thanks for replying.

I tried adding your code into my existing code, like this :

Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data Entry (B)")
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
Dim BkMkRng As Range
objWord.Visible = True
objWord.Documents.Open "C:\Users\" & Environ("username") & "\Desktop\xxx\xxxN"
objWord.ActiveDocument.Unprotect Password:="xxx"
With objWord.ActiveDocument



.FormFields("pr1").Range.Text = ws.Range("C28").Value

 If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
    End If
  .Fields.Update


objWord.ActiveDocument.Protect Password:="xxx", NoReset:=False, Type:=wdAllowOnlyFormFields
End With

Set objWord = Nothing
End Sub
But fieldcode still disappear. Am I inserting the codes into wrong way?
Reply With Quote