Sub sumDim i As IntegerDim sum As Integersum = 0DebugPrint 表格数: & WordSelectionTablesCountFor i = 1 To WordSelectionTablesCount sum = sum + WordSelectionTablesItemiRowsCount - 1 Dim thisTable A
This VBA macro calculates the total number of rows in all tables in the current Word document selection and prints it to the Immediate Window. It also includes a loop that can be used to perform additional actions on each table, such as modifying cell contents.
To use this macro, open the Visual Basic Editor in Word and paste the code into a new module. Then, select the tables in your document that you want to include in the count and run the macro.
Note that this macro assumes that the selection only contains tables and no other types of content. If there are other types of content in the selection, the macro may not work correctly. Also, the loop that modifies cell contents is currently commented out; remove the apostrophes to activate it.
原文地址: https://www.cveoy.top/t/topic/bW6z 著作权归作者所有。请勿转载和采集!