Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 03-05-2015, 01:03 AM
gmayor's Avatar
gmayor gmayor is offline Fieldupdate before saving and save document where documentname is resut of field values Windows 7 64bit Fieldupdate before saving and save document where documentname is resut of field values Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
field update, save as docx, save as pdf



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fieldupdate before saving and save document where documentname is resut of field values How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Fieldupdate before saving and save document where documentname is resut of field values Summing up values in a Single Merge Field Beowolf Mail Merge 1 03-07-2014 03:26 PM
Save merged document as concatenated merge field values texas791 Word VBA 4 02-25-2014 07:35 PM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM
Need to save QlikOCX Plugin as image while saving the PPT udaya.kumar PowerPoint 0 06-09-2012 11:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft