#1
|
|||
|
|||
Macro to Formatting Text Boxes
Hi there,
I wonder if there's any possibility to create a macro that would format a larger number of text boxes even though they are grouped. In fact, I deal with such grouped items on a daily basis, and because these are usually in large quantities, I'd like to use a macro. What is essential for me is that the text boxes must always have these font properties (character spacing): Scale = 100% Spacing = Normal Position = Normal No Kerning for fonts
Sub Ungroup() Dim xNmbr As Integer With ActiveDocument For xNmbr = .Shapes.Count To 1 Step -1 .Shapes(xNmbr).Select Set thisshape = .Shapes(xNmbr) With thisshape.WrapFormat .Type = wdWrapSquare If thisshape.Type = msoGroup Then thisshape.Ungroup End With Next End With End Sub
Sub SetTextBoxStyle() Dim objTextBox As Shape Dim objDoc As Document Application.ScreenUpdating = False Set objDoc = ActiveDocument For Each objTextBox In objDoc.Shapes ' Set line style. With objTextBox.Line .Visible = msoTrue .ForeColor.RGB = RGB(255, 255, 255) End With ' Set fill color. objTextBox.Fill.ForeColor.RGB = RGB(255, 255, 255) ' Set text color. objTextBox.TextFrame.TextRange.Font.TextColor.RGB = RGB(8, 8, 8) ' Set text size. objTextBox.TextFrame.TextRange.Font.Size = 10 ' Set font face. objTextBox.TextFrame.TextRange.Font.Name = "Arial Narrow" ' Set character spacing. objTextBox.TextFrame.TextRange.Font.Spacing = 0 ' Set character spacing. objTextBox.TextFrame.TextRange.Font.Scaling = 100 ' Set character spacing. objTextBox.TextFrame.TextRange.Font.Position = 0 Next objTextBox Application.ScreenUpdating = True End Sub Unfortunately, this process did not entirely work; it did ungroup all the text boxes. BUT it wouldn't successfully run the second macro, most likely because an object number got too large and thus the macro failed. Please, would you have any idea what might be the problem. Anyway, I really don't insist on running the first macro for ungrouping the textboxes, as they tend to disassemble in a quite chaotic way. I only need to set the spacing of characters in all text boxes (as quickly/easily as possible). Thanks a lot! Irene |
#2
|
||||
|
||||
How about you don't ungroup the shapes and switch to using a paragraph style in your shapes.
Code:
Sub SetTextBoxStyle() Dim oShape As Shape, objDoc As Document, oInnerShape As Shape Application.ScreenUpdating = False Set objDoc = ActiveDocument For Each oShape In objDoc.Shapes If oShape.Type = msoGroup Then For Each oInnerShape In oShape.GroupItems FormatAShape oInnerShape Next oInnerShape Else FormatAShape oShape End If Next oShape Application.ScreenUpdating = True End Sub Function FormatAShape(oShape As Shape) With oShape .Line.Visible = msoTrue .Line.ForeColor.RGB = RGB(255, 255, 255) ' Set line style. .Fill.ForeColor.RGB = RGB(255, 255, 255) ' Set fill color. If .TextFrame.HasText Then .TextFrame.TextRange.Font.Reset .TextFrame.TextRange.Style = "Normal" 'assumes style exists and has below attributes ' .TextFrame.TextRange.Font.TextColor.RGB = RGB(8, 8, 8) ' Set text color. ' .TextFrame.TextRange.Font.Size = 10 ' Set text size. ' .TextFrame.TextRange.Font.Name = "Arial Narrow" ' Set font face. ' .TextFrame.TextRange.Font.Spacing = 0 ' Set character spacing. ' .TextFrame.TextRange.Font.Scaling = 100 ' Set character spacing. ' .TextFrame.TextRange.Font.Position = 0 ' Set character spacing. End If End With End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
It Works!
Hi there,
sorry for being late for my response, as I wanted to try your macro properly, i.e. in several documents. I must say, it works! Thank you so much. For me, it works very well. The only thing I couldn't figure out is the font colour, size, and face, which remain untouched although altered in every Word document I formatted. However, I don't need that, since the character spacing is essential for my job. Thanks a lot! Much appreciated! |
#4
|
||||
|
||||
I wrote the code to avoid having to be specific about those attributes. If you make sure those attributes are already configured for the style you are choosing to apply then you don't need the individual lines setting colour, size, font name etc.
The code also includes a bunch of disabled lines which I put in there if you did want to activate them. You activate the lines by removing the ' single quote from the start of the line.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
character spacing, font formatting macro, textboxes |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
formatting photos within text boxes | ianmck | Drawing and Graphics | 5 | 06-28-2018 09:04 PM |
Macro to insert different sets of text at bookmark depending on sequence of selected check boxes | chipper09 | Word VBA | 0 | 06-21-2018 01:49 PM |
Drawing lines between text boxes which have actual text within the text boxes | RHODIUM | Word | 6 | 10-01-2016 04:43 PM |
Is there a way to anchor drop-down content control boxes so entering text doesn't change formatting? | TzarChasm | Word | 7 | 04-14-2016 06:28 PM |
Macro (or something) to run Spell Check within rich text content boxes in lock document | NMBELL | Word | 8 | 12-21-2015 04:09 PM |