How to save a new Excel Workbook, created by an Excel Macro

Hello,

My project involves using an Excel Macro to change data and Output the selected data. Currently, this is done using the execute macro feature, however I am struggling to find a way to save this output because it is created as a new Excel Document, rather than a new sheet. I have tried the save workbook feature, but it saves the old Excel Document, rather than the newly created one.

Here is the VBA code for the macro:

Sub Main()

Application.ScreenUpdating = True

Dim FileName As String
Dim SourceRange As Range

Sheets(“Input”).Select
Range(“A2”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets(“Output”).Select
Range(“A2”).Select
ActiveSheet.Paste
Sheets(“Output”).Select
Range(“A2”).Select
Range(Selection, Selection.End(xlDown)).Select
Set SourceRange = Selection

For Each Row In SourceRange.Rows
Sheets(“Output”).Select
Row.Cells(1, 1).Select
ActiveCell.Formula2R1C1 = _
“=IFS(AND(Input!RC[10]=”""",Input!RC[8]=""""),Input!RC[9],Input!RC[10]="""",Input!RC[8],Input!RC[10]<>"""",Input!RC[10])"
Next Row

For Each Row In SourceRange.Rows
Sheets(“Output”).Select
Row.Cells(1, 2).Select
ActiveCell = “A Careline engineer has been booked to attend your property.”

Next Row


Sheets("Output").Select
Application.CutCopyMode = False
Sheets("Output").Move

End Sub

and here is the Uipath studio workflow: Screenshot 2020-10-26 131721
Any help, whether it is on uipath or changing the macro, will be helpful. Thank you!

Hi @deguy42,

Is having the data in an other sheet of the same file a requirement?

Else you can just use Move File Activity to Rename the created file as you like

Well the new data will have to be completely seperate from the old data. So it has to be a new Excel file. Is there a way to just save this new file that is created?

If the new Excel is on your screen, click on the window and send F12 Hotkey, this will open the Save As window and you can put the Path+Name and save

Hello,

I managed to code this into the VBA instead, which made things easier.
Just added: ActiveWorkbook.SaveAs FileName:=".xlsx"

Thank you for the help though!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.