cancel
Showing results for 
Search instead for 
Did you mean: 

How to add rows in MS Word ?

SwatiAgrawal
Level 5
Hi,

I have a table in MS Word. This table has multiple rows with multiple boxes. Each box has an "x" and "y" which is obtained by hit and trial method.
I want to add a row in between the table, after a specific row. After adding that row, I want to merge all the cells in that row. 
Not sure how I can achieve this.
I tried using Add Rows - MS Word VBO action but it adds row at the end of the table. This doesn't help me out.
Looking forward for help from you guys.

Thanks in advance !!


------------------------------
Swati Agrawal
------------------------------
1 BEST ANSWER

Helpful Answers

Hey Swati,

You are right that the "Add Table Rows" action adds new rows at the end of any given table in the word document. I have listed down the steps below in order to achieve your use case.

Solution Implementation:

In order to achieve this, we can extend the "MS Word VBO" by creating a separate action within it and you can call it as "Add Table Rows At Position". This action will be having the following input parameters:

  1. Handle (Number) : The data item having the handle value in the instance dictionary that needs to be queried. (This you can get from Create Instance action)

  2. Document Name (Text) : The document name of the current workbook which the Blur Prism bot is operating on. (This you can get from Open Workbook action)

  3. Table Number (Number) : The table element index used in the current workbook to identify the table.

  4. Cell X (Number) : The row number of the cell which will be considered as the reference for deciding the rows to be added below or above. (The index value starts from 1)

  5. Cell Y (Number) : The column number of the cell which will be considered as the reference for deciding the rows to be added below or above. (The index value starts from 1)

  6. Number Of Rows (Number) : The number of rows which need to be added below or above the reference cell. (The value should be greater than 0)

  7. Insert After Mode (Flag) : The flag value determining whether the rows need to be added above or below the reference cell. (If the value is True, rows will be added below the reference cell otherwise the rows will be added above the reference cell)


Refer to the below workflow for more information:

11166.png
11167.png

Now, add a custom code stage with the following Input parameters and the code as shown below. No output parameters are required:

11168.png
11169.png
Code:

Dim doc as Object = GetDocument(Handle,Document_Name)
doc.Tables.Item(Table_Number).Cell(Cell_Y_Number,Cell_X_Number).Range.Select

If Number_Of_Rows = 0 Then Throw New Exception("Number of rows must be greater than zero.")

If Insert_After_Mode Then

     For i = 1 To Number_Of_Rows

        doc.ActiveWindow.Selection.InsertRowsBelow()

     Next

Else

     For i = 1 To Number_Of_Rows

         doc.ActiveWindow.Selection.InsertRowsAbove()

     Next

End If


You can publish this action and run the same from Process Studio to check your results.




Some of the test results are shown below:


Scenario I: The table I have has three rows by default and I want to add three rows below the second row:

11170.png11171.png
Result of the action is:

11172.png
Let us know if this helps you out!

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant
Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

View answer in original post

3 REPLIES 3

Hey Swati,

You are right that the "Add Table Rows" action adds new rows at the end of any given table in the word document. I have listed down the steps below in order to achieve your use case.

Solution Implementation:

In order to achieve this, we can extend the "MS Word VBO" by creating a separate action within it and you can call it as "Add Table Rows At Position". This action will be having the following input parameters:

  1. Handle (Number) : The data item having the handle value in the instance dictionary that needs to be queried. (This you can get from Create Instance action)

  2. Document Name (Text) : The document name of the current workbook which the Blur Prism bot is operating on. (This you can get from Open Workbook action)

  3. Table Number (Number) : The table element index used in the current workbook to identify the table.

  4. Cell X (Number) : The row number of the cell which will be considered as the reference for deciding the rows to be added below or above. (The index value starts from 1)

  5. Cell Y (Number) : The column number of the cell which will be considered as the reference for deciding the rows to be added below or above. (The index value starts from 1)

  6. Number Of Rows (Number) : The number of rows which need to be added below or above the reference cell. (The value should be greater than 0)

  7. Insert After Mode (Flag) : The flag value determining whether the rows need to be added above or below the reference cell. (If the value is True, rows will be added below the reference cell otherwise the rows will be added above the reference cell)


Refer to the below workflow for more information:

11166.png
11167.png

Now, add a custom code stage with the following Input parameters and the code as shown below. No output parameters are required:

11168.png
11169.png
Code:

Dim doc as Object = GetDocument(Handle,Document_Name)
doc.Tables.Item(Table_Number).Cell(Cell_Y_Number,Cell_X_Number).Range.Select

If Number_Of_Rows = 0 Then Throw New Exception("Number of rows must be greater than zero.")

If Insert_After_Mode Then

     For i = 1 To Number_Of_Rows

        doc.ActiveWindow.Selection.InsertRowsBelow()

     Next

Else

     For i = 1 To Number_Of_Rows

         doc.ActiveWindow.Selection.InsertRowsAbove()

     Next

End If


You can publish this action and run the same from Process Studio to check your results.




Some of the test results are shown below:


Scenario I: The table I have has three rows by default and I want to add three rows below the second row:

11170.png11171.png
Result of the action is:

11172.png
Let us know if this helps you out!

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant
Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

Hi Devneet,

Thanks.
Actually when I run this, then it says complile error in code. Not sure why.

Still finding out.


------------------------------
Swati Agrawal
------------------------------

Hi Swati,

I cross checked the code and it is working on my system with the same solution provided. You can perhaps check the variable names as in some instances instead of handle and document name I am using Handle and Document Name. You can also let us know what is the exact error you are getting if you are not able to implement the same.

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant
Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.