The following should work if you change the form as indicated. I have left in the line for testing with the colon in place:
Code:
Option Explicit
Sub FileSave()
If Not ActiveDocument = ThisDocument Then
Call FileSaveAs
Else
ActiveDocument.Save
End If
lbl_Exit:
Exit Sub
End Sub
Sub FileSaveAs()
Dim iAsk As Long
Dim strPath As String
Dim oCC As ContentControl
If Not ActiveDocument = ThisDocument Then
For Each oCC In ActiveDocument.ContentControls
If oCC.Title = "Geboortenaam" _
Or oCC.Title = "SAP nummer" _
Or oCC.Title = "Besluitsoort" Then
If oCC.Range.Text = oCC.PlaceholderText Then
MsgBox "Complete the '" & oCC.Title & "' field"
GoTo lbl_Exit
End If
End If
Next oCC
UpdateAllFields
iAsk = MsgBox("Save as PDF Format?", vbYesNoCancel)
Select Case iAsk
Case vbYes
With Dialogs(wdDialogFileSaveAs)
.Name = GetFilename(ActiveDocument) & ".pdf"
.Format = wdFormatPDF
.Show
End With
Case vbNo
With Dialogs(wdDialogFileSaveAs)
.Name = GetFilename(ActiveDocument) & ".docx"
.Format = wdFormatXMLDocument
.Show
End With
Case Else
MsgBox "Document Not Saved!"
End Select
Else
Dialogs(wdDialogFileSaveAs).Show
End If
lbl_Exit:
Exit Sub
End Sub
Private Sub UpdateAllFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
lbl_Exit:
Exit Sub
End Sub
Private Function GetFilename(oDoc As Document) As String
Dim oCC As ContentControl
Dim strName As String
Dim strNumber As String
Dim strDate As String
Dim strBesluitsoort As String
With oDoc
For Each oCC In .ContentControls
If oCC.Title = "Geboortenaam" Then strName = oCC.Range.Text
If oCC.Title = "SAP nummer" Then strNumber = oCC.Range.Text
If oCC.Title = "Besluitsoort" Then strBesluitsoort = oCC.Range.Text
'If oCC.Title = "Besluitsoort" Then strBesluitsoort = Replace(oCC.Range.Text, Chr(58), "")
Next oCC
strDate = Format(Date, "yyyymmdd")
GetFilename = "VBP " & strDate & Chr(32) & strName & Chr(32) & strNumber & Chr(32) & strBesluitsoort
End With
lbl_Exit:
Exit Function
End Function