+ Reply to Thread
Results 1 to 2 of 2

Different Hyperlinks as source folders to copy all files in new folder

  1. #1
    Registered User
    Join Date
    10-19-2017
    Location
    France
    MS-Off Ver
    2013
    Posts
    1

    Different Hyperlinks as source folders to copy all files in new folder

    Dear,
    I have currently a table with hyperlinks to different folders, in each of those folders I can have more than 1 file. Based on the selected cells with the different hyperlinks I would like to copy all related files to 1 common folders.
    There is already an example to copy pdf files to one folder but I need to use different hyperlinks with differents (when selected) path where more than 1 file must be selected an copied to the folder.

    I tried to combine those 2 codes but did not get it to work unfortenatelly


    Public Sub CopyFileHH()
    Dim objFSO As Object
    Dim objFil As Object
    Dim rngCell As Range
    Dim strOldDir As String
    Const strNewDir As String = "C:3\Desktop\New folder\Try\New folder\"

    strOldDir = "C:\Desktop\New folder\Try\"

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    On Error Resume Next
    For Each rngCell In Selection
    Set objFil = objFSO.GetFile(strOldDir & rngCell.Hyperlinks(1).Address)
    objFil.Copy strNewDir
    Next rngCell
    On Error GoTo 0
    End Sub

    Sub copyfilesa()
    Dim source_file As String, dest_file As String
    Dim source_path As String, dest_path As String
    Dim i As Long, file_array As Variant

    source_path = "C:\Desktop\New folder\Try\"
    dest_path = "C:\Desktop\New folder\Try\New folder\"



    source_file = Dir(source_path & "\" & "*.*")
    Do Until source_file = ""
    If Not IsArray(file_array) Then
    ReDim file_array(0) As Variant
    Else
    ReDim Preserve file_array(UBound(file_array) + 1) As Variant
    End If

    file_array(UBound(file_array)) = source_file
    source_file = Dir
    Loop

    'If new folder is not existed, create it.
    If Dir(dest_path, 16) = "" Then MkDir dest_path '16=vbDirectory

    For i = LBound(file_array) To UBound(file_array)
    FileCopy source_path & "\" & file_array(i), dest_path & "\" & file_array(i)
    Next i
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Different Hyperlinks as source folders to copy all files in new folder

    You can edit your code and add code tags to the VBA code you supplied.

    AA CodeTags.jpg

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 08-05-2015, 11:45 PM
  2. [SOLVED] Copy certain files from Source folder to Destination folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2015, 08:56 PM
  3. Needs macro to copy excel files from folders, subfolders to new folder
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:53 AM
  4. Use Excel VBA to Copy multiple files from different source folders to different folders
    By mm1234mail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 01:17 PM
  5. [SOLVED] Copy List of Hyperlinked Files From Source to Target Folder
    By ugadawgs311 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-01-2014, 03:21 AM
  6. Copy Files from one folder to different folders based on pdf file name
    By jtammyg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2014, 11:49 AM
  7. Replies: 1
    Last Post: 09-12-2013, 09:23 PM

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