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:
@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.
Use the “Attach Window” activity to target the Microsoft Word application window.
Use the “Click” activity to click on the table in the Word document to select it.
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.
Use the “Save Document” activity to save the modified document.
Close the Word application using the “Close Application” activity.
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()
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
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:
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()
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
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.