View Single Post
 
Old 07-17-2014, 03:24 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following. It's still not apparent, though, why you want to use the SaveAs dialogue given that you expressed a desire for a 'silent' save and that the .ExportAsFixedFormat method allows you to force the saved PDF to open so you can do the securing without the need for an additional process.
Code:
Private Sub CommandButton1_Click()
Dim MBxAns
Dim i As Long
Dim Fldr As String
Dim StrNm As String
Dim vrtSelectedItem As Variant
Dim wdDoc As Document
 MBxAns = MsgBox("Did you update the SWMS Number?", vbYesNo, "Bunny Check...")
If MBxAns <> vbYes Then Exit Sub
 With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = "G:\Admin - MASTER\Customers\"
    .AllowMultiSelect = False
    .Title = "Select Destination Folder for the SWMS"
    If .Show = -2 Then Exit Sub
    Fldr = .SelectedItems(1)
End With
 MBxAns = MsgBox(Fldr, vbOKCancel, "The Destination Folder is...")
If MBxAns = vbCancel Then Exit Sub
 
    With Application.FileDialog(msoFileDialogFilePicker)
        .InitialFileName = "G:\QMS\OH&S"
        .Title = "Select the SWMS Templates"
        .AllowMultiSelect = True
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
                Set wdDoc = Documents.Open(FileName:=vrtSelectedItem)
                With wdDoc
                    .Fields.Update
                    StrNm = "SWMS " & .Bookmarks("SWMSNumber").Range.Text & " " & _
                        .Bookmarks("SWMSType").Range.Text & " - " & _
                        .Bookmarks("PrimaryContractor").Range.Text & " - " & _
                        .Bookmarks("ProjectName").Range.Text
                        .BuiltInDocumentProperties("Title") = StrNm
                        .BuiltInDocumentProperties("Subject") = .Bookmarks("SWMSType").Range.Text
                    With Dialogs(wdDialogFileSaveAs)
                        .Name = Fldr & StrNm & ".pdf"
                        .Format = wdFormatPDF
                        .Show
                    End With
                    .Close SaveChanges:=False
                End With
            Next
        End If
    End With
    MsgBox "remember to secure the PDF before sending"
    'ActiveDocument.Close SaveChanges:=False
End Sub
Note that I've commented-out the last line for testing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote