Dear all,
I want to merge cells in an excel file.
I tried to invoke code that I took from excel after recording a macro.
But i get errors about not declaring in the code.
I can not find anywhere a solution.
I can not install belareva activities about excel in the machine, so I got to do it with code.
Could you please help? The code is the below:
Range("A1:C1").Select
Selection.NumberFormat = "@"
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("D1:F1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
pllo2ptk
(Swoodie)
February 13, 2020, 9:35am
2
Did you record VBA and try to invoke it “Invoke Code” Activity?
Invoke Code starts only VB (for new version of UiPath, if Project is in C#, also C#).
You can create VBA (macro file) and run this from UiPath - Execute macro in Excel activities.
Yes, exactly. I recorded the VBA and then I user invoke code to run it.
pllo2ptk
(Swoodie)
February 13, 2020, 9:37am
5
He cannot install any packages
pllo2ptk
(Swoodie)
February 13, 2020, 9:37am
6
You can create VBA (macro file) and run this from UiPath - Execute macro in Excel activities .
AshwinS2
(Ashwin S)
February 13, 2020, 9:41am
7
Hi @the.christopoulos
you can use execute macro and pass the function name and try
Thanks
Ashwin S
@pllo2ptk @AshwinS2
I can not execute macros also because of security policy in the Organization.
I need to invoke vba code, but I do not know exactly how it should be.
Does anybody know how to write vba code for invoking just to merge two different ranges of cells in the active excel which is already open , because I am inside excel application scope activity?
pllo2ptk
(Swoodie)
February 13, 2020, 10:07am
9
You can always create your own activity for merging files (write it in C#).
There is no possibility to invoke VBA code from the Uipath directly.
@pllo2ptk
Why not? Are you sure? Then, what is Invoke code activity for?
pllo2ptk
(Swoodie)
February 13, 2020, 10:18am
11
Invoke Code is for run Visual Basic (not Visual Basic for Application) code.
Anyway, you can try find guides how to manipulate excel file with VB.
mz3bel
(Mohssine HILAL)
February 13, 2020, 4:25pm
12
Hi @the.christopoulos
Why don’t you use the merge activity on UiPath ?
@mz3bel Which one exactly is this ? I do not have any merge for excel. Only merge datatable
mz3bel
(Mohssine HILAL)
February 13, 2020, 4:58pm
14
@the.christopoulos
Yes, you read the excel file and store your data on a datatable, than use merge to merge the data you want…
@mz3bel I just want to merge cells in excel, in order to make A1:C1 to show like 1 cell
Not in datatable.
@bcorrea I put the code you mentioned and I get the below errors:
bcorrea
(Bruno Correa)
February 14, 2020, 6:27pm
19
i imagined you had imported the namespace already, you need to add this import to your project:
Microsoft.Office.Interop.Excel
@bcorrea In the available namespaces for import there is not such namespace.
bcorrea
(Bruno Correa)
February 17, 2020, 1:36pm
21
it does not begin with Excel… it is Microsoft.Office.Interop.Excel