PDA

View Full Version : Change font size of bullet in table



clhare
09-23-2009, 06:47 AM
I have a document that has text and tables in it. In both areas, there are bullets, em dashes, and en dashes. Is it possible to change the size of the bullets, em dashes, and en dashes only in the table the cursor is in (leaving those outside the table or those in other tables as is)?

For example, the bullet text in the table may be 10 pt and the bullet itself is 11.5 pt. Could I change the bullet itself throughout the table to 13 pt using VBA?

fumei
09-23-2009, 03:47 PM
Use Styles properly. In other words, have a style for the tables, a different style for outside the tables.

Doing it through VBA means - if I understand you correctly - changing the format structure "manually" (independent of the Style).

clhare
09-24-2009, 04:03 AM
Yes, that is correct. The documents are already set up. The user wants to change the bullets only in specific tables.

If it is not possible to get at the bullet itself when found in a table and change its size, is it possible to determine if the text in the table is in a specific (bullet) style and if so, change the style?

fumei
09-24-2009, 09:40 AM
Yes. Click "Change Table Bullet Font" on the top toolbar.

To exaggerate and show the difference, the bullets - for ONLY the bullets in the table cell - are changed from Regular, 12 pts to Bold Italic 16 pts. It could be whatever change you want.

The procedure for "Change Table Bullet Font" uses one line of code. One line.

fumei
09-24-2009, 09:54 AM
To demonstrate further the proper use of styles, click "Change Table Bullet Font" on the top toolbar of this version.

Notice that the first cell bullets change, but the second cell bullets do not change.

That is because the second cell uses a different style, even though it looks exactly like the first cell.

This code (three lines), changes a specific style - and ONLY that style - in the table. Thus, the first cell (which does have that style) is changed, but the second (which uses a different style) is not changed.



For some reasons, I can not get this to accept an attachment.

clhare
09-24-2009, 11:10 AM
Your .doc file is password protected. What password do I use to view the macros?

fumei
09-24-2009, 11:27 AM
I am not going to give you that. I posted it to show that the answer to your question:

"If it is not possible to get at the bullet itself when found in a table and change its size, is it possible to determine if the text in the table is in a specific (bullet) style and if so, change the style?"

is, simply, yes. It is possible. Further, that it is very straightforward. I hinted that with stating it took one line. You have been using VBA for a bit now, give it try.

At the very least, post what logic - what requirements - are needed. If you can figure out (and this one is easy) what the logic needs are, then the actual code is minimal.

Which, it is. In the posted demo (I still can not attach the second version for some reason), it is - as stated - ONE line of code. One.

Tell me what you think that line may be, or better yet, try to do it yourself. Post what you tried, and if it is not quite right, i will help you fix it.

Hint: it uses precisely what I suggested be used. Proper Styles. It simply changes one style to another style using ONE line of code.

fumei
09-24-2009, 11:30 AM
Here is the second version.

clhare
09-24-2009, 02:56 PM
Ok, I'll see what I can figure out. Thanks for the clues! Time to put on my detective hat!

clhare
09-28-2009, 07:49 AM
Well, I haven't figured out the one line of code that replaces the styles, and it's driving me crazy!

In your second sample document, I did notice that if I copied the text from the first cell into all four cells of the table (so they all use the same style), the macro did not update all occurrences of the style in the table, only those in the first cell. I tried creating my own macro that would replace styles in the entire selected table only, and found that my macro (definitely more than 1 line of code) also does not update all occurrences in the table. I can't figure out why it's not working correctly. My file is attached.

Also, your sample document has a second style already created that has the larger bullet. When I tried manually creating a new style with a larger bullet (based on the existing style), I lost the bullet entirely in the existing style. I have no idea why that is happening either.

:hairpull:

fumei
09-28-2009, 11:08 AM
Well, I haven't figured out the one line of code that replaces the styles, and it's driving me crazy!

The existing style is "InTable_1". This one line changes Cell(1,1) to "InTable_2".
ActiveDocument.Tables(1).Cell(1, 1) .Range.Style = "InTable_2"
Notice that it is explicit, yes, it changes Cell(1,1) only.

In your second sample document, I did notice that if I copied the text from the first cell into all four cells of the table (so they all use the same style), the macro did not update all occurrences of the style in the table, only those in the first cell.Yes, that would be true, as the code is - again - explicit to Cell(1,1).
If ActiveDocument.Tables(1).Cell(1, 1) _
.Range.Style = "InTable_1" Then
ActiveDocument.Tables(1).Cell(1, 1) _
.Range.Style = "InTable_2"
End If
This can be achieved if you use a cell object, then a For Each statement for each cell in the table. Hint: use Table(x).Range.Cells.

However....be VERY careful, as when you copy you must make sure you are not including any paragraph marks that are NOT the defined style. For example, if the last paragraph mark is NOT InTable_1, then it will not work. Although it could of course be made to work.

fumei
09-28-2009, 12:00 PM
When I tried manually creating a new style with a larger bullet (based on the existing style), I lost the bullet entirely in the existing style. Please describe - in detail - exactly how you are attempting to do this. It is done through the Styles dialog.

clhare
09-30-2009, 04:33 AM
Re creating the new styles, what am I doing wrong??

I select Format > Styles & Formatting, then click on the New Style button. Then I name it, base it on the existing bullet style and click on the Format button and select Numbering. From the Bullets and Numbering window, I selected the Bulleted tab and then clicked on the Font button to change the size, then OK'd my way back to the document. The original bullet style no longer had a bullet. So I tried it again and this time went to the Outline Numbered tab and changed the font size. Again, the original bullet style no longer had a bullet.

clhare
09-30-2009, 05:13 AM
If I create a new style in a macro, it doesn't mess up the original style. But I'd still need to somehow change the bullet size in the new style--which doesn't work right when I try to do it manually. Is there no way to change the bullet size in the macro that create the new style?

ActiveDocument.Styles.Add Name:="Bullet SS-Ppt", Type:= _
wdStyleTypeParagraph
With ActiveDocument.Styles("Bullet SS-Ppt")
.AutomaticallyUpdate = False
.BaseStyle = "Bullet SS"
.NextParagraphStyle = "Bullet SS-Ppt"
End With

fumei
09-30-2009, 11:33 AM
IMO, it is NOT a good idea to create Styles via code. Why are you doing that?

clhare
09-30-2009, 12:01 PM
Well, I was thinking of creating the styles via macro since there's alot of documents that would use these styles. If the macro created the styles, it would be easiet way to get them into any document.

Otherwise, is it possible to have the styles in a template (in Startup) and have a macro in that template that can copy the styles to the active document (assuming I can create the styles without messing up the existing styles)?