Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2018, 03:02 AM
shu shu is offline run through tables and format these Windows 10 run through tables and format these Office 2016
Novice
run through tables and format these
 
Join Date: Jun 2018
Posts: 6
shu is on a distinguished road
Unhappy run through tables and format these

Hey

I'm new with vba word. I want to run trough tables and change some properties. I have a document with around 100 tables and when i start the makro, the word document has an error and shuts down after 20 - 30 tables. Can someone tell me why?

This is my code for it:



Code:
Sub Tabellen_formatieren()

Dim i As Integer
    
For i = 1 To ActiveDocument.Tables.Count
             ActiveDocument.Tables(i).Select
         
        With ActiveDocument.Tables(i).Range.Font
        .Name = "Arial"
        .Size = 10
        .ColorIndex = wdBlack
        End With
        
       With ActiveDocument.Tables(i)
       .PreferredWidthType = wdPreferredWidthPercent
       .PreferredWidth = 100
       End With
              
Next

End Sub

Last edited by macropod; 06-07-2018 at 04:35 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 06-07-2018, 05:02 PM
macropod's Avatar
macropod macropod is offline run through tables and format these Windows 7 64bit run through tables and format these 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

With many tables to process, Word is probably not getting enough breathing space for its housekeeping. You're also unecessarily selecting each table, which only adds to the processing overheads. Try:
Code:
Sub Tabellen_formatieren()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  For i = 1 To .Tables.Count
    With .Tables(i)
      With .Range.Font
        .Name = "Arial"
        .Size = 10
        .ColorIndex = wdBlack
      End With
      .PreferredWidthType = wdPreferredWidthPercent
      .PreferredWidth = 100
    End With
    If i Mod 25 = 0 Then DoEvents
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-07-2018, 10:31 PM
shu shu is offline run through tables and format these Windows 10 run through tables and format these Office 2016
Novice
run through tables and format these
 
Join Date: Jun 2018
Posts: 6
shu is on a distinguished road
Default

It's working, many thanks

BR shu
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
run through tables and format these VBA code to format a document containing tables rasika99 Word VBA 3 12-12-2014 04:16 AM
[Rich Text Format] - about tables and pictures cambalinho Word 0 07-24-2013 01:17 PM
run through tables and format these Format of the Tables protocoder Word VBA 2 06-28-2011 02:51 AM
run through tables and format these Auto-Format Tables of Contents/Figures judicial85 Word 3 12-25-2010 02:02 AM
Copying format between tables. daeron Word Tables 0 06-11-2010 12:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:08 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