Prev: Shortcut keys and UserForm
Next: blank table row
From: Nick on 20 Jan 2010 08:54 Dave, I was wondering if you could recommend a quick way to modify the following code so it also starts on the second table, like was done with the bold code. Dim myTable As Table For Each myTable In ActiveDocument.Tables myTable.Select Selection.Style = ActiveDocument.Styles("Custom Table") Selection.Font.Name = "Times New Roman" Selection.Font.Size = "12" Selection.Rows.Alignment = wdAlignRowCenter Next myTable ActiveDocument.Repaginate Thanks again for all your help. DaveLett wrote: Hi Nick,Yes, it is known issue with merged cells. 19-Jan-10 Hi Nick, Yes, it is known issue with merged cells. You can try the following: Dim lTbl As Long Dim lCl As Long For lTbl = 2 To ActiveDocument.Tables.Count With ActiveDocument.Tables(lTbl) For lCl = 1 To .Range.Cells.Count If .Range.Cells(lCl).RowIndex = 1 Then ..Range.Cells(lCl).Range.Font.Bold = True End If Next lCl End With Next lTbl HTH, Dave Previous Posts In This Thread: Submitted via EggHeadCafe - Software Developer Portal of Choice HOW TO GET RID OF THE "XXexmodulae.exe" Trojan http://www.eggheadcafe.com/tutorials/aspnet/4d1b500f-23ce-4a5f-a18c-1d4261d01e86/how-to-get-rid-of-the-xx.aspx
From: Jay Freedman on 20 Jan 2010 10:38 Replace the For Each loop with one that uses the index into the Tables collection, and start at 2 -- something like this: Dim TableIndex As Long For Each TableIndex = 2 To ActiveDocument.Tables.Count ActiveDocument.Tables(TableIndex).Select ' then the formatting as before Next TableIndex Also, I'd recommend *not* selecting the table and using Selection to do the formatting. VBA gives you access to things that aren't selected, with the advantage that the document doesn't have to scroll and redraw the screen, which is a slow operation. Sample code: Dim TableIndex As Long Dim myTable As Table For Each TableIndex = 2 To ActiveDocument.Tables.Count Set myTable = ActiveDocument.Tables(TableIndex) With myTable .Range.Style = ActiveDocument.Styles("Custom Table") .Range.Font.Name = "Times New Roman" .Range.Font.Size = 12 .Rows.Alignment = wdAlignRowCenter End With Next TableIndex -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. Nick wrote: > Dave, > > I was wondering if you could recommend a quick way to modify the > following code so it also starts on the second table, like was done > with the bold code. > > Dim myTable As Table > For Each myTable In ActiveDocument.Tables > myTable.Select > Selection.Style = ActiveDocument.Styles("Custom Table") > Selection.Font.Name = "Times New Roman" > Selection.Font.Size = "12" > Selection.Rows.Alignment = wdAlignRowCenter > Next myTable > ActiveDocument.Repaginate > > Thanks again for all your help. > > > > DaveLett wrote: > > Hi Nick,Yes, it is known issue with merged cells. > 19-Jan-10 > > Hi Nick, > Yes, it is known issue with merged cells. You can try the following: > > Dim lTbl As Long > Dim lCl As Long > > For lTbl = 2 To ActiveDocument.Tables.Count > With ActiveDocument.Tables(lTbl) > For lCl = 1 To .Range.Cells.Count > If .Range.Cells(lCl).RowIndex = 1 Then > .Range.Cells(lCl).Range.Font.Bold = True > End If > Next lCl > End With > Next lTbl > > HTH, > Dave > > Previous Posts In This Thread: > > > Submitted via EggHeadCafe - Software Developer Portal of Choice > HOW TO GET RID OF THE "XXexmodulae.exe" Trojan > http://www.eggheadcafe.com/tutorials/aspnet/4d1b500f-23ce-4a5f-a18c-1d4261d01e86/how-to-get-rid-of-the-xx.aspx
From: Jay Freedman on 20 Jan 2010 10:45 Oops, copy/paste error. The For statement should not have an "Each" in it. Instead, use For TableIndex = 2 To ActiveDocument.Tables.Count Jay Freedman wrote: > Replace the For Each loop with one that uses the index into the Tables > collection, and start at 2 -- something like this: > > Dim TableIndex As Long > For Each TableIndex = 2 To ActiveDocument.Tables.Count > ActiveDocument.Tables(TableIndex).Select > ' then the formatting as before > Next TableIndex > > Also, I'd recommend *not* selecting the table and using Selection to > do the formatting. VBA gives you access to things that aren't > selected, with the advantage that the document doesn't have to scroll > and redraw the screen, which is a slow operation. Sample code: > > Dim TableIndex As Long > Dim myTable As Table > For Each TableIndex = 2 To ActiveDocument.Tables.Count > Set myTable = ActiveDocument.Tables(TableIndex) > With myTable > .Range.Style = ActiveDocument.Styles("Custom Table") > .Range.Font.Name = "Times New Roman" > .Range.Font.Size = 12 > .Rows.Alignment = wdAlignRowCenter > End With > Next TableIndex > > > Nick wrote: >> Dave, >> >> I was wondering if you could recommend a quick way to modify the >> following code so it also starts on the second table, like was done >> with the bold code. >> >> Dim myTable As Table >> For Each myTable In ActiveDocument.Tables >> myTable.Select >> Selection.Style = ActiveDocument.Styles("Custom Table") >> Selection.Font.Name = "Times New Roman" >> Selection.Font.Size = "12" >> Selection.Rows.Alignment = wdAlignRowCenter >> Next myTable >> ActiveDocument.Repaginate >> >> Thanks again for all your help. >> >> >> >> DaveLett wrote: >> >> Hi Nick,Yes, it is known issue with merged cells. >> 19-Jan-10 >> >> Hi Nick, >> Yes, it is known issue with merged cells. You can try the following: >> >> Dim lTbl As Long >> Dim lCl As Long >> >> For lTbl = 2 To ActiveDocument.Tables.Count >> With ActiveDocument.Tables(lTbl) >> For lCl = 1 To .Range.Cells.Count >> If .Range.Cells(lCl).RowIndex = 1 Then >> .Range.Cells(lCl).Range.Font.Bold = True >> End If >> Next lCl >> End With >> Next lTbl >> >> HTH, >> Dave >> >> Previous Posts In This Thread: >> >> >> Submitted via EggHeadCafe - Software Developer Portal of Choice >> HOW TO GET RID OF THE "XXexmodulae.exe" Trojan >> http://www.eggheadcafe.com/tutorials/aspnet/4d1b500f-23ce-4a5f-a18c-1d4261d01e86/how-to-get-rid-of-the-xx.aspx
|
Pages: 1 Prev: Shortcut keys and UserForm Next: blank table row |