Deleting Tables Containing a Range of Columns - vba

I am going through several hundred Word documents that contain dozens of tables each. I need to delete all of the tables that contain more than three columns. The entire table needs to be removed from the document. I cannot simply delete all of the tables in the document (a Macro for which I already have) because these documents contain bulleted information in table format.
Alternatively, a Macro for converting tables with three or fewer columns into text would also get the job done.

Figured it out.
Sub RemoveDataTables()
For Each Table In ActiveDocument.Tables
If Table.Columns.Count > 3 Then
Table.Delete
End If
Next
End Sub

Related

How to find number of columns in MS Word table with document set for right to left

I have a MS Word document containing tables with Arabic text (i.e. the document is set for Right to Left). However I am working with this document on a computer set for English. There is a table with multiple rows and 3 columns. In some of the rows all three columns might be merged and in some other may be 2 columns.
I am trying to traverse through the table each row at a time as I want to automatically change some contents in the table if the row has two cells merged or none of the cells merged.
However both the below lines of VBA code throws the error
"Run time error 5941, The requested member of the collection does not
exist"
ThisDocument.Tables(1).Columns.Count
ThisDocument.Tables(1).Rows.Count
The above two lines work perfectly fine on a document with English text i.e. set for Left to Right.

How to Know a Word Table's Index Number?

I have this large Word doc with 100 tables. However, I only need to use 3 tables for a VB script, example:
Set tbl = wdDoc.Tables(1)
Where this refers to the first table in the Word doc. However, the 3 tables are in the middle of the document. How may I know their "index number" instead of manually checking if they are the nth table in the document?
I assign names to the Title property of tables I need to identify. Then I loop through all the tables in the document and pick out the one with the Title I want.

complex VBA to remove duplicates from multiple pages and then delete blank rows looping all sheets

I've spent hours on the internet trying to work something out but can not get a vba fix to work on a complex sheet like mine! Your help would be appreciated.
For all these queries I'd like to loop through all sheets, but skip the sheets named "timekeeper code", "bill date" & "summary" - these names will always be the same but I can not name the sheets. The script needs to loop as the names and quantity will vary.
On all other sheets it will loop I need to select the range "A1002:A2003" and if there is a duplicate delete the row.
I also need to do the same for range "A2005:A3006".
Please note that both of these ranges are with in tables but again the table names can't be named as they will vary.
I'm not sure if it helps but the full table range for A1002:A2003 is A1002:B2003
and the full table range for A2005:A3006 is A2005:AD3006
I can also not go from A1002 straight to A3006 as some values will be shown in both ranges but I will need them both
looping the same sheets,
I then need to delete all rows from A1001 upwards to the last used cell where the cell value is = ""
I have a very limited skill on VBA and quite a complex query so I'm basically stuck starting from scratch so any code you have to do this would be amazing!
I hope this makes sense.
Many thnaks
First google entry solves your problem:
Delete all duplicate rows Excel vba
now you have to generate a loop around this function to target the correct sheets.

Multi page Word tables to PowerPoint while preserving headers

I have a macro that moves all pictures and tables to a PowerPoint while capturing the figure name and number as well as the table name and number. I am pasting the tables in as .Shapes.PasteSpecial(ppPasteMetafilePicture).
This has worked great in the past but I have come across about 150 documents that need to be converted that contain tables that span more than one page. When the macro pastes the table it cuts off at the first page.
If I split the table using the macro it does not carry over the headers.
What I want is to be able to do is split this table into multiple slides per Word document page that it is on and include the headers of the table.
Since you're pasting as a picture the only possibility is to EDIT the Word tables. You'd need to read how many rows comprise the table header, copy those rows, deactivate the table header setting, then paste the row(s) at the top of each page. Then you can copy each page. At the end, close the document without saving so that the original still has the table headers.

Delete Entire Rows That Have Multiple Matching Cells

I created a macro that will copy over some information from one sheet in my workbook to another to match some criteria so I may import the info into a program. Only problem is after the macro runs, there are some blank rows and a couple duplicates. I have 12 columns of info but I would like to have the macro look at and compare entries in columns D,E,F,G and L with the row above them. So D2,E2,F2,G2 and L2 would be compared to D1,E1,F1,G1 and L1. IF all five of the entries in these cells match that of the previous row, then delete the entire row.
I've found some codes that match one cell or looks for duplicates in a certain column but nothing to look and match multiple columns and I'm so new to this that I'm having trouble even getting started.
Any and all input is welcome.
You're going to have to put in the logic of your program yourself but use something like:
worksheets("Sheet1").range("A1").offset(i, 0).resize(1, colnum).delete Shift:=xlUp
An easy way to find the commands you need is to record a macro and see what Excel uses to build that macro.