Consulting

Results 1 to 3 of 3

Thread: Open Attachments and Convert/Combine into single PDF

  1. #1
    VBAX Newbie
    Joined
    May 2015
    Posts
    3
    Location

    Open Attachments and Convert/Combine into single PDF

    Hello. I am fairly new to VBA in general and am trying to implement a solution that takes the active word document, prompts the user to add attachements (usually PDFs, can be more than 1 document), and combines them into a single PDF.

    This is all in Office 2013.

    The active document is created via a User Form that I created. It acts as the first page in the "combined" document. I do have Adobe Acrobat XI standard which has the "combine files into PDF" capability that I want to utilize.

    To quickly summarize the workflow I'd like to create:
    1) User opens the document template and fills out the user form.
    2) The first page in the document package is now created. (This is where I'm at right now)
    3) The user can click to run a macro to add attachments to the document. I'm not sure the best way to tackle this (copy the filepaths and somehow feed that info to Acrobat and launch the "combine files into PDF"?)
    4) Maybe the above step needs to be broken into 2 macros, 1 to add/open the attachments and the other to combine them into the PDF?

    Sorry if I am rambling a bit as you can see my mind is all over the place on this one.

    Thanks in advance for your help.

  2. #2
    VBAX Newbie
    Joined
    May 2015
    Posts
    3
    Location
    I have this inside the macro so far, it doesn't seem to be working : (

    Sub newfold()
    Dim strNewFolderName As String
    strNewFolderName = "RFI Compile " & (Month(Now())) & " " & Year(Now)
    If Len(Dir("c:\Temp" & strNewFolderName, vbDirectory)) = 0 Then
    MkDir ("c:\Temp" & strNewFolderName)
    End If

    End Sub


    Sub Add_Attachments()
    Dim PathName As String
    PathName = ("RFI Compile " & MonthName(Month(Now())) & " " & Year(Now))
    Const msoFileDialogOpen = 1


    Set objWord = CreateObject("Word.Application")


    objWord.ChangeFileOpenDirectory ("C:\")


    objWord.FileDialog(msoFileDialogOpen).Title = "Select the attachments"
    objWord.FileDialog(msoFileDialogOpen).AllowMultiSelect = True


    If objWord.FileDialog(msoFileDialogOpen).Show = -1 Then
    objWord.WindowState = 2
    For Each objFile In objWord.FileDialog(msoFileDialogOpen).SelectedItems
    objFile.SaveAs2 fileName:="c:\Temp" & strNewFolderName & "\" & Split(objFile.Name, ".")(0) & ".pdf", _
    FileFormat:=wdFormatPDF
    Next

    End If

  3. #3
    VBAX Newbie
    Joined
    May 2015
    Posts
    3
    Location
    Still running into an Object Required error at the bolded/underlined point in the code:

    Sub Add_Attachments()
    Dim strNewFolderName As String
    Dim fd As FileDialog

    strNewFolderName = "\RFI Compile " & (Month(Now())) & " " & Year(Now)
    If Len(Dir("c:\Temp" & strNewFolderName, vbDirectory)) = 0 Then
    MkDir ("c:\Temp" & strNewFolderName)
    End If

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    Dim vrtSelectedItem As Variant

    With fd
    .AllowMultiSelect = True


    If .Show = -1 Then
    'Step through each string in the FileDialogSelectedItems collection.
    For Each vrtSelectedItem In .SelectedItems


    'vrtSelectedItem is aString that contains the path of each selected item.
    'You can use any file I/O functions that you want to work with this path.
    'This example displays the path in a message box.
    'MsgBox "Selected item's path: " & vrtSelectedItem
    SelectedItem.SaveAs2 fileName:="c:\Temp" & strNewFolderName & "\" & Document.Name & ".pdf", _
    FileFormat:=wdFormatPDF


    Next
    'If the user presses Cancel...
    Else
    End If
    End With


    'Set the object variable to Nothing.
    Set fd = Nothing


    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •