+ Reply to Thread
Results 1 to 3 of 3

Coping PDF Files with Excel

Hybrid View

  1. #1
    Forum Contributor CobraLAD's Avatar
    Join Date
    07-23-2007
    Location
    Boksburg, South Africa
    MS-Off Ver
    Office 2019
    Posts
    346

    Coping PDF Files with Excel

    I manage to create a nice file copier, but I have 2 problems, Please Help

    I'm using a userform.

    I have a button to select the main folder where all the pdf files must go to, and then the location is saved in the registry, so everytime I run the userform the main folder is selected. I am using this code, and it works 100%
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    Dim vrtSelectedItem As Variant
    With fd
        .Title = "Please select folder"
        If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
                TextBox1.Value = .SelectedItems(1) & IIf(Right(CurDir, 1) <> "\", "\", "")
            Next vrtSelectedItem
        Else
        End If
    End With
    
    SaveSetting APPNAME, "Settings", "TextBox1", TextBox1.Value
    then I select the folder where the pdf files is with a second button, and only PDF files is selected. I am using this code, and it works 100%
    ListBox1.Clear
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        .Title = "Please select folder"
        If .Show = -1 Then
            ListFiles = Dir("*.pdf")
            Do While Not ListFiles = ""
            ListBox1.AddItem ListFiles
            ListFiles = Dir()
            Loop
        Else
        End If
    End With
    the Listbox is set to MultiSelect = fmMultiSelectMulti and ListStyle = fmListStyleOption

    Then I copy the selected item to the main folder
    I am using this code, and it works 100%
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) = True Then
        FileCopy ListBox1.List(i), TextBox1.Value & ListBox1.List(i)
        Else
        MsgBox "File already in List"
        End If
    Next i
    MsgBox "All selected PDF Files copied to " & """" & TextBox1.Value & """"
    ListBox1.Clear
    Q1. I want to use the file browser not the filedialog picker. I manage to select the folder, but it lists all the file. How do I get it to select only pdf files, and I also want to list the files in a Listbox on Userform

    the code for the browser.

    Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
      
    Public Type BROWSEINFO
        hOwner As Long
        pidlRoot As Long
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As Long
        lParam As Long
        iImage As Long
    End Type
    
    Function GetDirectory(Optional Msg) As String
        Dim bInfo As BROWSEINFO
        Dim path As String
        Dim r As Long, x As Long, pos As Integer
        bInfo.pidlRoot = 0&
        bInfo.lpszTitle = "Select a folder."
        bInfo.ulFlags = &H1
        x = SHBrowseForFolder(bInfo)
        path = Space$(512)
        r = SHGetPathFromIDList(ByVal x, ByVal path)
        If r Then
            pos = InStr(path, Chr$(0))
            GetDirectory = Left(path, pos - 1)
        Else
            GetDirectory = ""
      End If
    End Function
    
    Sub BrowseFolder()
    Dim Directory As String
    Dim f As String
    Dim r As Long
    Directory = GetDirectory
    If Directory = "" Then Exit Sub
    If Right(Directory, 1) <> "\" Then Directory = Directory & "\"
    'MsgBox Directory
    r = 0
    f = Dir(Directory, Range("E1").Value)
    Do While f <> ""
        r = r + 1
        Cells(r, 1) = f
        f = Dir
    Loop
    End Sub
    Q2. How do I set the button that copies the files to check if the files is already in the main folder.
    Last edited by CobraLAD; 02-23-2010 at 07:52 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coping PDF Files with Excel

    Hello CobraLAD,

    It would be easier to make the necessary changes, if the workbook were available. Posting the workbook will also reduce the question and answers needed to develop a solution quickly.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor CobraLAD's Avatar
    Join Date
    07-23-2007
    Location
    Boksburg, South Africa
    MS-Off Ver
    Office 2019
    Posts
    346

    Re: Coping PDF Files with Excel

    I solved Q1 of selecting only pdf files, using browser and listing them in a Listbox

    I need help with:

    The workook must check if file(s) listed in listbox is already in the main folder before coping.

    Workbook attached.
    Attached Files Attached Files
    Last edited by CobraLAD; 02-24-2010 at 03:40 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1