View Single Post
 
Old 07-15-2014, 10:58 PM
smndnm smndnm is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

I don't want to open the PDFs, I need to batch process them to apply security settings, it is an attempt to open an instance of Adobe pro locally if not already open.

I am so close, I can taste it...
There are only two issues with the code below and it is still valid inside this thread.

issue1 = It throws an exception at the"msoFileDialogFilePicker" stage when the user presses cancel. I cannot make the previous solution work (If .Show = -2 Then Exit Sub).
Issue2 = It doesn't remember the variable "target1" when I save the PDF and thus won't select the chosen location. it works when all docs are local on my laptop, but it has fallen over when it tested on the network.

When it works correctly, I'll change the .Show for the .Execute, which means the user has nothing to do except acknowledge the end.

I would very much like some help with identifying what changes need to be made to fix these two issues.

Code:
Private Sub CommandButton1_Click()

Dim MBxAns1 As Long
Dim MBxAns2 As Long
Dim i As Long
Dim target1 As String
Dim filenametitle As String
Dim StrNm As String
Dim vrtSelectedItem As Variant

MBxAns1 = MsgBox("Did you update the SWMS Number?", vbOKCancel, "Bunny Check...")
If MBxAns1 = vbCancel 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
    target1 = .SelectedItems(1)
End With

MBxAns2 = MsgBox(target1, vbOKCancel, "The Destination Folder is...")
If MBxAns2 = 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

                Documents.Open FileName:=vrtSelectedItem
                Options.DefaultFilePath(wdDocumentsPath) = target1
                
                With ActiveDocument
                .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
                filenametitle = ActiveDocument.BuiltInDocumentProperties("Title")
                 End With
                
                
                With Dialogs(wdDialogFileSaveAs)
                .Name = filenametitle
                .Format = wdFormatPDF
                .Show
                '.Execute
                ActiveDocument.Close SaveChanges:=False


    End With


        Next

        Else

        End If

    End With
    
    MsgBox "remember to secure the PDF before sending"
    ActiveDocument.Close SaveChanges:=False
    
End Sub
Regards from Queensland
Reply With Quote