not really a result...
I am clearly well out of my depth. I have exactly the same result... with the addition of not knowing how to preselect the starting folder when selecting the destination folder (a sub-folder of the preselected folder)
It doesn't correctly select the destination SaveAs folder, even though the last instruction is to open the destination folder (which it does correctly).
It opens the Templates folder on my local drive.
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
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
MBxAns2 = MsgBox(GetFolder, 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) = GetFolder
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")
Call Shell("explorer.exe """ & GetFolder & "", vbNormalFocus)
End Sub
I can feel how close this is to being a great result, but I can't seem to get through this issue. To my mind, it reads correctly, but the evidence shows that it doesn't work. I really would like to better understand why this isn't working...and I don't understand how GetFolder and oFolder are interacting, but I'll get there.
Regards from Queensland