(Solved) – Duplicate workbook and execute macro in that file

(solved)-–-duplicate-workbook-and-execute-macro-in-that-file

I would like to create a VBA code that copies the workbook in a separate workbook (workbook2) and converts in that second workbook all the formulas to values, the coversion should not be done in workbook 1 (the active one). I found a code that does the conversion but I don’t know how to make it execute it in workbook 2. Then I should save this workbook 2. Any Ideas? Below the code

Sub ConvertFormulasToValuesAllWorksheets()
On Error Resume Next
    Dim ws As Worksheet, rng As Range



    For Each ws In ActiveWorkbook.Worksheets

    For Each rng In ws.UsedRange

        If rng.HasFormula Then

            rng.Formula = rng.Value

        End If

    Next rng

    Next ws

    ActiveWorkbook.SaveAs Filename:= _
    "C:UsersmyusidDesktopmyfolderworkbook2.xlsx" _
     , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False ' need to 
     change the name of the folder
     Application.DisplayAlerts = True


      On Error GoTo 0
      End Sub

Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *