Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 11-12-2015, 01:17 AM
1van 1van is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Nov 2015
Posts: 2
1van is on a distinguished road
Default Apply styles in word table

Hello, I need help with making a macro for repeatedly adding specific styles to parts of the table, to loop trough the document until the text "%string" is found.



So I would need to apply a style, move a few 'tabs', add a new style, move 'tabs', until "%string" is found:

Code:
    Selection.Style = ActiveDocument.Styles("style1")
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Style = ActiveDocument.Styles("style1")
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
this is the number of 'tabs' that is required to position over the right part of the table.

Thank you. Ivan.
Reply With Quote
  #2  
Old 11-12-2015, 04:28 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 787
gmaxey will become famous soon enough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngIndex As Long
  Do
    Selection.Style = ActiveDocument.Styles("style 1")
    For lngIndex = 1 To 6
      Selection.MoveRight Unit:=wdCell
      If Left(Selection.Cells(1).Range.Text, Len(Selection.Cells(1).Range.Text) - 2) = "%string" Then Exit Do
    Next lngIndex
  Loop
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-17-2015, 11:05 AM
1van 1van is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Nov 2015
Posts: 2
1van is on a distinguished road
Default

works like a charm, thank you!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word Table - Select More than 1 Column at a time - Apply Formatting jc491 Word VBA 12 09-24-2015 06:03 AM
Word 2013: My custom table styles disappeared from Gallery sinz54 Word Tables 1 03-13-2015 05:02 PM
how to apply table style WITHOUT setting it as a table? dylansmith Excel 9 05-16-2014 07:25 PM
How 2 Save Table Properties & Apply to other table Popeye.Tom Word Tables 1 04-24-2013 09:44 PM
Paragraph space before - can styles apply it intelligently? timpani Word 7 10-23-2012 04:08 PM


All times are GMT -7. The time now is 06:50 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft