Removing Table Gridlines in Word

Hi Community,

I have a very simple ask, is there a way to remove the hidden Table Layout (Gridlines) from a word document without compromising the format.
This is one request from our customer as they are getting a Word Document from their system with a very tightly packed layout (using table) which makes it problematic to edit. They want us to remove these Table Gridlines / make it easier to edit for adding details. However, the format should not be compromised as it is an Billing Document.
I have attached a sample screenshot of how the document looks with & without the Table gridlines.
With Gridlines:


Without Gridlines:

Any help would be really appreciated!

Thanks,
AB

Hi @abhat

  1. Use “Word Application Scope” and specify the file path of the Word document.
  2. Invoke VBA
- Code: Sub HideTableGridlines()
                      ActiveDocument.Tables.Gridlines = False
                  End Sub
  1. Use “Save Document As” property to save the word.

Hope it helps!!
Regards,

Hi,

  1. Use the “Attach Window” activity to target the Microsoft Word application window.
  2. Use the “Click” activity to click on the “Layout” tab in the Ribbon.
  3. Use the “Click” activity to click on the “View Gridlines” button in the “Table” group to toggle off the gridlines.
  4. Use the “Save Document” activity to save the modified document.
  5. Close the Word application using the “Close Application” activity.

I hope this will help you

@rlgandu - We don’t want to Hide/display the gridlines, we want to remove them completely.
The reason for that is the issue customer faces while filling the documents.
For Eg: I want to fill the Claim# in the form and it is 11 characters, however the space can just accommodate 3 characters the rest of them will disappear after filling and, If we try to move those gridlines the complete format will change and we don’t want that.

@abhat

Use this VBA code:

Sub RemoveGridlines()
    ActiveDocument.Tables.Gridlines = False
End Sub

@abhat

Try the below thread it was showing for excel but invoke the VBA code for word and give a try

Regards

@abhat

Try this procedure hope it helps

  1. Use the “Attach Window” activity to target the Microsoft Word application window.
  2. Use the “Click” activity to click on the table in the Word document to select it.
  3. Use the “Send Hotkey” activity and send the hotkey “Ctrl + Shift + 8” to toggle the table gridlines off. This hotkey combination is used to hide/show gridlines in Word.
  4. Use the “Save Document” activity to save the modified document.
  5. Close the Word application using the “Close Application” activity.

@abhat

You can use invoke code activity and simple execute the command related to removing gridlines


Dim wordApp As New Microsoft.Office.Interop.Word.Application()
wordApp.Visible = True
Dim document As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open("C:\Path\To\Your\Document.docx")
For Each table As Microsoft.Office.Interop.Word.Table In document.Tables
   For Each border As Microsoft.Office.Interop.Word.Border In table.Borders
        border.LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone
   Next
Next
document.Save()
document.Close()
wordApp.Quit()

cheers

Hi @Anil_G

I gave it a try, but it is not removing the Gridlines/boder it is changing the style I believe the gridlines are still present in the background. We need to remove them, that is what the challenge is

Thnaks!

Hi @abhat

Did you try this

  1. Use “Word Application Scope” and specify the file path of the Word document.
  2. Invoke VBA
- Code: Sub HideTableGridlines()
                      ActiveDocument.Tables.Gridlines = False
                  End Sub
  1. Use “Save Document As” property to save the word.

Regards,

Hi @Parvathy

I’m not sure on this as the Invoke VBA is available for Excel and not Word. I tried adding that to Word but it throws an error. Can you share a sample xaml with us:

Thanks,
AB

@abhat

You have to use Invoke VBA.

Regards,

@Parvathy - both the Invoke VBA are giving the same error that they need to be used in Excel Application Scope

Thanks,
Abhinav

@abhat

Use Invoke Code activity. Pass the code in a text file.

Regards,

@abhat

Use “invoke code” activity.

@abhat

Try this…this should be working as expected


Dim wordApp As New Microsoft.Office.Interop.Word.Application()
wordApp.Visible = True
Dim document As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open("C:\Path\To\Your\Document.docx")
For Each table As Microsoft.Office.Interop.Word.Table In document.Tables
      table.Borders.Enable = 0
Next
document.Save()
document.Close()
wordApp.Quit()

cheers

@abhat

Hi,

To remove the table gridlines in a Word document without compromising the format using UiPath’s Invoke Code activity, you can use the following VBA code snippet:
Sub RemoveTableGridlines(FileName As String)
Dim tbl As Table
Documents.Open FileName
For Each tbl In ActiveDocument.Tables
tbl.Range.Tables(1).Borders.Enable = False
Next tbl
ActiveDocument.Save
ActiveDocument.Close
End Sub

Hi @Anil_G

Tried the other approach as well, it just hides the border, the table and everything is still there. I’m thinking of tryin got remove the table see if that works.

Let me know your thoughts

Thanks,
Abhinav

@abhat

For the table are there only boarders or inline and outlines as well?

If both then we can combine precious and current code and try it to remove everything together

If you remove table and use a template as is then it would be the best option

Cheers

@abhat

Did it work? If yes please mark as solution to close the loop.

Regards,