Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-17-2014, 07:05 AM
CircleG CircleG is offline Macro to select and update all tables in document Windows 7 64bit Macro to select and update all tables in document Office 2007
Novice
Macro to select and update all tables in document
 
Join Date: Oct 2014
Posts: 3
CircleG is on a distinguished road
Default Macro to select and update all tables in document

Hi:



I have a macro to update tables to make them ready to import into Excel. The macro works great, but only for the first table in the document. Is there a way for the macro to move to each table and do the updates? Sample doument with several tables with the macro is attached.

Thanks for your help.
Attached Files
File Type: docx WordTableMacro.docx (13.0 KB, 13 views)
Reply With Quote
  #2  
Old 10-17-2014, 09:28 AM
gmaxey gmaxey is offline Macro to select and update all tables in document Windows 7 32bit Macro to select and update all tables in document Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub RemoveBorders()
Dim oTbl As Word.Table
  For Each oTbl In ActiveDocument.Tables
    With oTbl.Range
      .Shading.Texture = wdTextureNone
      .Shading.ForegroundPatternColor = wdColorAutomatic
      .Shading.BackgroundPatternColor = wdColorAutomatic
      .Font.Color = wdColorAutomatic
    End With
    With oTbl
      .Borders(wdBorderTop).LineStyle = wdLineStyleNone
      .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
      .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
      .Borders(wdBorderRight).LineStyle = wdLineStyleNone
      .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
    End With
  Next oTbl
     
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-17-2014, 12:12 PM
CircleG CircleG is offline Macro to select and update all tables in document Windows 7 64bit Macro to select and update all tables in document Office 2007
Novice
Macro to select and update all tables in document
 
Join Date: Oct 2014
Posts: 3
CircleG is on a distinguished road
Default Macro to select and update all tables in document

Thanks, gmaxey. The code works great. I also have a combined macro with several macros to run at the same time that I need to update all the tables in the document. I tried puting the new code in the combined macro, but that didn't work. So I tried putting it in each macro in the combined macro, but I keep getting error messages and not all the macros are running. To say I'm not real good at this is putting it mildly.

A text document with the combined macro and the individual macros is attached. The one you have already fixed is the last one (Remove Borders).

Thanks and have a great weekend.
Attached Files
File Type: txt CreateForExcel.txt (2.5 KB, 8 views)
Reply With Quote
  #4  
Old 10-17-2014, 12:27 PM
gmaxey gmaxey is offline Macro to select and update all tables in document Windows 7 32bit Macro to select and update all tables in document Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

CircleG,

This is not intended to offend you. My general philosophy for my participation in this forums is loosely related to the adage "Give a man a fish and he eats for a day; Teach a man to fish and he eats for a lifetime." Your question was how do I loop through tables. I've showed you how to do that. For you to now come back and ask me to fix your entire project is not in keeping with that philosophy. If I do all of the work without compensation then you keep getting free fish and I don't eat at all.

If there is a particular issue that you get stumped over then I recommend you asked about it in a new thread. Otherwise back to the grindstone ;-)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 10-17-2014, 01:36 PM
CircleG CircleG is offline Macro to select and update all tables in document Windows 7 64bit Macro to select and update all tables in document Office 2007
Novice
Macro to select and update all tables in document
 
Join Date: Oct 2014
Posts: 3
CircleG is on a distinguished road
Default

I agree with your philosophy and I did try to apply your coding to the combined macro, but couldn't figure it out. I didn't understand if each individual macro in the combined macro needed to be updated or if just something in the combined macro itself. I finally put the macro you fixed as the last macro in the combined macro grouping and it worked fine. But still don't know if that is how it is supposed to work or just luck.

I have been able to adjust existing macros to new situations, but sometime I still don't really understand how to dig up the the worm to put on the hook.
Thanks for your help. Have a great weekend.

Post has been marked as Solved.
Reply With Quote
  #6  
Old 10-17-2014, 01:40 PM
gmaxey gmaxey is offline Macro to select and update all tables in document Windows 7 32bit Macro to select and update all tables in document Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

CircleG, all of the little I know has been a combination of monkey see, monkey do; trial and error or just luck. It can be frustrating, but it is one way to learn.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 10-17-2014 at 07:40 PM.
Reply With Quote
  #7  
Old 10-17-2014, 07:25 PM
macropod's Avatar
macropod macropod is offline Macro to select and update all tables in document Windows 7 64bit Macro to select and update all tables in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by CircleG View Post
I also have a combined macro with several macros to run at the same time that I need to update all the tables in the document. I tried puting the new code in the combined macro, but that didn't work. So I tried putting it in each macro in the combined macro, but I keep getting error messages and not all the macros are running. To say I'm not real good at this is putting it mildly.
The first thing you need to do is to fix the errors in your code. Even as stand-along macros, your ReplaceParagraphMarks and RemoveHeaders macros won't run. Both are missing:
Code:
    End With
  Next oTbl
If you then look at your ReplaceParagraphMarks, RemoveHeaders and RemoveBorders macros, you'll see that all have this much in common:
Code:
Dim oTbl As Word.Table
For Each oTbl In ActiveDocument.Tables
  With oTbl
    
  End With
Next oTbl
If you wanted to combine those three macros, all you need is the above code, plus whatever's between the With ... End With parts from each of those three macro (and, of course, a sub to contain all the code). That said, there are some other issues you need to address with the ReplaceParagraphMarks and RemoveHeaders macros, too. For example:
Selection.Rows.HeadingFormat = wdToggle
would only work on a Selection (i.e. something that is selected), but your code isn't selecting anything (and doesn't need to). Furthermore, it would actually add a header row if a selected row wasn't already one... Being inside a loop only means it'll keep toggling the same selection's header property on/off. Similarly, your Find/Replace code operates completely independently of any tables that it might be in - it works on the entire document. All that happens is that the loop keeps running the same document-wide process.

Finally, if you want to keep the macros separate, you could change lines like:
Application.Run MacroName:="ReplaceBullets"
to just:
ReplaceBullets
or, to make it more apparent another sub is being called:
Call ReplaceBullets
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to select and update all tables in document Macro to create tables around all images in document lsmcal1984 Word VBA 4 12-01-2013 06:58 PM
select statement in macro Nicolette Excel 1 11-19-2013 01:38 AM
Macro to select and update all tables in document Macro for select words? Megan Sprack Word 1 08-23-2012 03:03 PM
Macro to select and update all tables in document Macro to select tables ubns Word VBA 5 04-15-2012 11:44 PM
Macro to select and update all tables in document Can't select shapes via macro TishyMouse Word VBA 3 04-13-2012 03:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:54 AM.


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