Results 1 to 10 of 10

Copy file PDF/DWG/DXF from local server to a PC specific folder

Threaded View

  1. #1
    Registered User
    Join Date
    12-07-2022
    Location
    Italy
    MS-Off Ver
    Microsoft 365 for Business
    Posts
    8

    Question Copy file PDF/DWG/DXF from local server to a PC specific folder

    SEARCH AND COPY.xlsm

    Hi all

    I've an Excel file with VBA macro inside...I use this file to search and copy specific files into a local nas server.

    The problem is that the macro is configured to search in a specific location on the server nas
    "\\nas01\Archivio Disegni\DV1\"
    But I want the macro to search both in "Archivio Disegni" and also in its sub folders... As you can see on the atthached file, the sSourcePath is
    sSourcePath = "\\nas01\Archivio Disegni\DV1\"
    , so it is set to search in the specific DV! folder in Archivio Disegni,...and I "simply" want the macro to search in both in "Archivio Disegni" and also in its sub folders...all the file i'll serach has unique name, such as DV0001 and so on...every file I search has a unique name, so it's impossible to have duplicate file errors etc

    The excel file is then set to return "not exist" if the file does not exist on the server, or PDF copied if it exists, etc as you can see in the attached file. but this is already working

    This is the macro I have
    Sub CopyDWG()
        Dim iRow As Integer         ' ROW COUNTER.
        Dim sSourcePath As String
        Dim sDestinationPath As String
        Dim sFileType As String
       
        Dim bContinue As Boolean
       
        bContinue = True
        iRow = 5
       
        ' THE SOURCE AND DESTINATION FOLDER WITH PATH.
        sSourcePath = "\\nas01\Archivio Disegni\DV1\"
        sDestinationPath = "C:\Users\luca\Desktop\DRW\"
       
        sFileType = ".dwg"      ' TRY WITH OTHER FILE TYPES LIKE ".pdf".
     
        ' LOOP THROUGH COLUMN "D" TO PICK THE FILES.
        While bContinue
       
            If Len(Range("A" & CStr(iRow)).Value) = 0 Then    ' DO NOTHING IF THE COLUMN IS BLANK.
                MsgBox "Process executed" ' DONE.
                bContinue = False
            Else
                ' CHECK IF FILES EXISTS.
               
                If Len(Dir(sSourcePath & Range("A" & CStr(iRow)).Value & sFileType)) = 0 Then
                    Range("D" & CStr(iRow)).Value = "Does Not Exists"
                    Range("D" & CStr(iRow)).Font.Bold = True
                Else
                    Range("D" & CStr(iRow)).Value = "DWG Copied"
                    Range("D" & CStr(iRow)).Font.Bold = False
               
                    If Trim(sDestinationPath) <> "" Then
                        Dim objFSO
                        Set objFSO = CreateObject("scripting.filesystemobject")
                       
                        ' CHECK IF DESTINATION FOLDER EXISTS.
                        If objFSO.FolderExists(sDestinationPath) = False Then
                            MsgBox sDestinationPath & " Does Not Exists"
                            Exit Sub
                        End If
                       
                        ' METHOD 1) - USING "CopyFile" METHOD TO COPY THE FILES.
                        objFSO.CopyFile Source:=sSourcePath & Range("A" & CStr(iRow)).Value & _
                            sFileType, Destination:=sDestinationPath
                       
                      End If
                End If
            End If
         
           iRow = iRow + 1      ' INCREMENT ROW COUNTER.
        Wend
    End Sub
    Can someone help me with this, I cannot find any solution since i'm not that good with VBA.

    Thanks all
    Best Regards
    Luca
    Last edited by luca_061088; 12-14-2022 at 04:06 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] need a VBA code to open, and save a file in specific folder using cell file paths
    By JSD100 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-27-2022, 10:49 AM
  2. Replies: 8
    Last Post: 12-02-2019, 03:42 PM
  3. Copying worksheets from specific folder into a specific file
    By RavindraK in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-19-2019, 02:14 PM
  4. Macro to copy server file into local folder, and change data sources to this new file
    By rickywangca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2019, 11:18 AM
  5. [SOLVED] Open newest folder and specific file in the folder
    By timtim91 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2017, 11:55 AM
  6. [SOLVED] Save as xlsm file with specific name & specific folder
    By namialus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 03:32 AM
  7. Replies: 4
    Last Post: 12-30-2011, 11:24 AM

Tags for this Thread

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