• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

CLONE FILES WITHOUT FORMULAS ONLY VALUES.

Rui Pires

Member
Hello everyone ;

I have several files("Animais_1;Animais_2;.....") that contain several worksheets that can contain some formulas.
My goal is to get a file named macro can clone these files into the folder
"NEW_FILES" with the same names but without any formula, only the values.
Many thanks to anyone who can help me.
PS: attached code that manages only within a file
 

Attachments

  • ScreenHunter_04 Feb. 10 19.17.jpg
    ScreenHunter_04 Feb. 10 19.17.jpg
    83.9 KB · Views: 4
Assuming there aren't any issues with protected files/sheets, this should do it. Bulk of code taken from here.
Code:
Option Explicit

Sub CloneFiles()
Dim myBook As Workbook
Dim ws As Worksheet
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim fNum As Long, CalcMode As Long

    'Fill in the path\folder where the files are
    MyPath = "C:\Users\Ron\test"
   
    'Add a slash at the end if the user forget it
    If Right(MyPath, 1) <> "\" Then
        MyPath = MyPath & "\"
    End If

    'If there are no Excel files in the folder exit the sub
    FilesInPath = Dir(MyPath & "*.xl*")
    If FilesInPath = "" Then
        MsgBox "No files found"
        Exit Sub
    End If

    'Fill the array(myFiles)with the list of Excel files in the folder
    fNum = 0
    Do While FilesInPath <> ""
        fNum = fNum + 1
        ReDim Preserve MyFiles(1 To fNum)
        MyFiles(fNum) = FilesInPath
        FilesInPath = Dir()
    Loop

    'Change ScreenUpdating, Calculation and EnableEvents
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
    End With
   
    'Loop through all files in the array(myFiles)
    If fNum > 0 Then
        For fNum = LBound(MyFiles) To UBound(MyFiles)
            Set myBook = Nothing
            On Error Resume Next
            Set myBook = Workbooks.Open(MyPath & MyFiles(fNum))
            On Error GoTo 0

            If Not myBook Is Nothing Then
                For Each ws In myBook.Worksheets
                    ws.UsedRange.Copy
                    ws.UsedRange.PasteSpecial xlPasteValues
                Next ws
                myBook.SaveAs MyPath & "Cloned_" & myBook.Name
                myBook.Close
            End If
        Next fNum
    End If
   
ExitTheSub:
    'Restore ScreenUpdating, Calculation and EnableEvents
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = CalcMode
    End With

End Sub
 
Back
Top