Hi,
Thanks for the help so far... much appreciated! There was more code behind the button but I didn't figure it would play a part. I've now made a button with simply that line in it and it seems to have exported with the fields still completed. So, it would suggest my code is at fault.
Here's the full code:
Private Sub CommandButton3_Click()
'Application.ScreenUpdating = False
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect Password:="development"
'ActiveDocument.FormFields("I_OpEncompass").Result = "Yes"
If ActiveDocument.Variables("DASHAdded") = True Then ' Do we need to remove the DASH form?
ActiveDocument.Sections(2).Range.Delete
ActiveDocument.StoryRanges(wdMainTextStory).Select
With Selection
.Find.Text = "If you require this risk assessment, add it using the button on the menu. It will be removed by the MASH before sending to external agencies, if appropriate."
.Find.Execute
.Delete
.TypeText "A risk assessment was completed, but has been removed as part of Operation Encompass." & (Chr(11)) & (Chr(11))
End With
End If
' Export the file as a PDF. Error handler ensures the section is put back if the user cancels the dialog
On Error Resume Next ' Stops errors on XP, and retores removed Section G
Application.Dialogs(wdDialogExportAsFixedFormat).Show
If ActiveDocument.Variables("DASHAdded") = True Then ' Do we need to put the DASH form back?
ActiveDocument.Undo
ActiveDocument.Undo
ActiveDocument.Undo
ActiveDocument.Undo
End If
'ActiveDocument.Protect Password:="development", NoReset:=True, Type:=wdAllowOnlyFormFields
Unload Me
UserForm1.Show vbModeless
'Application.ScreenUpdating = True
End Sub
Basically, I need to export a PDF of a sanitised version of the document. The code should check if a document variable is true, and if so delete the contents of a section and replace a bit of text. In all circumstances, export to PDF, and if that section was removed then to undo those steps to restore the document back to how it was post-export.
Hope this gives a bit more information...