Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2021, 08:06 PM
ez1138 ez1138 is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2019
Novice
Multiple tables in Word, converting working Excel macro
 
Join Date: Apr 2021
Posts: 3
ez1138 is on a distinguished road
Default Multiple tables in Word, converting working Excel macro

Hi, I have multiple tables within a Word document. Below is my working Excel VBA code. How do I convert it to Word for a table name "Table_Implemented"? Also, since I use the Power Automate "Populate a Word Document", is there a way to run the macro automatically once the document is created?



Thanks for any insight!!!

Code:
Sub deleteRow()
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False

'declare variables
Dim deleteRow As Long
Dim ws As Worksheet

'set objects
Set ws = ActiveSheet

For deleteRow = ws.Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1

If ws.Range("A" & deleteRow).Value = "Not Implemented" Then
Rows(deleteRow).EntireRow.Delete
End If

Next deleteRow

Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True

Last edited by macropod; 04-13-2021 at 09:37 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 04-13-2021, 08:28 PM
macropod's Avatar
macropod macropod is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Processing tables in Word is entirely different from processing ranges (however described) in Excel. For basic table row deletion in Word see, for example:
https://www.msofficeforums.com/150021-post2.html
See also:
https://www.msofficeforums.com/word-...ell-first.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-13-2021, 09:34 PM
ez1138 ez1138 is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2019
Novice
Multiple tables in Word, converting working Excel macro
 
Join Date: Apr 2021
Posts: 3
ez1138 is on a distinguished road
Default

Thanks!

Using the second link example, where/how would I specify a specific table name versus all tables? Using an example of Table_NotImplemented.

Thanks again!

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 2/12/2018
Dim oTbl As Table
Dim lngIndex As Long
  For Each oTbl In ActiveDocument.Tables
    For lngIndex = oTbl.Rows.Count To 1 Step -1
       If Left(oTbl.Cell(lngIndex, 1).Range.Text, Len(oTbl.Cell(lngIndex, 1).Range.Text) - 2) = "$" Then
         oTbl.Rows(lngIndex).Delete
       End If
    Next
  Next
lbl_Exit:
  Exit Sub
End Sub

Last edited by macropod; 04-13-2021 at 09:38 PM. Reason: Added code tags
Reply With Quote
  #4  
Old 04-13-2021, 09:44 PM
macropod's Avatar
macropod macropod is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Word tables don't have a 'name' property. They do, however, have a 'title' property which you can access via 'Alt Text' on the tables properties dialogue box. They can also be titled via VBA.

If you want to refer to a particular table, you'd ordinarily identify it by its index number, a bookmark that has been applied to it, or by using Find to identifying content unique to that table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-14-2021, 04:33 AM
ez1138 ez1138 is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2019
Novice
Multiple tables in Word, converting working Excel macro
 
Join Date: Apr 2021
Posts: 3
ez1138 is on a distinguished road
Default

Makes sense. I did add the title in the 'Alt Text' area for each table. Using the code from your original post, second example, how/where would I enter the table name (alt text)? Thanks again!

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, Microsoft Word Help, Tips and Tutorials @ The Anchorage, 2/12/2018
Dim oTbl As Table
Dim lngIndex As Long
  For Each oTbl In ActiveDocument.Tables
    For lngIndex = oTbl.Rows.Count To 1 Step -1
       If Left(oTbl.Cell(lngIndex, 1).Range.Text, Len(oTbl.Cell(lngIndex, 1).Range.Text) - 2) = "$" Then
         oTbl.Rows(lngIndex).Delete
       End If
    Next
  Next
lbl_Exit:
  Exit Sub
End Sub

Last edited by macropod; 04-14-2021 at 04:34 AM. Reason: Added code tags
Reply With Quote
  #6  
Old 04-14-2021, 04:39 AM
macropod's Avatar
macropod macropod is offline Multiple tables in Word, converting working Excel macro Windows 10 Multiple tables in Word, converting working Excel macro Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See:
https://www.msofficeforums.com/word-...es-tables.html
Bookmarked tables are easier to work with:
https://www.msofficeforums.com/word-...ame-table.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to insert multiple photos into separate tables Photoinserts Word VBA 0 11-12-2018 08:30 PM
Multiple tables in Word, converting working Excel macro replacing multiple ranges in excel with tables in word from top to bottom modiria50989 Word VBA 5 09-13-2017 04:01 PM
Multiple tables in Word, converting working Excel macro Creating multiple tables VBA from Excel to Word francesco Word VBA 1 01-07-2016 04:08 AM
Multiple tables in Word, converting working Excel macro Copying Multiple tables from excel into a single word document dineshtgs Word Tables 1 04-07-2011 01:27 AM
Multiple tables in Word, converting working Excel macro working with excel tables in MS word radman154 Word Tables 1 03-25-2011 12:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft