Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2021, 07:09 AM
effimera effimera is offline Macro to Formatting Text Boxes Windows 10 Macro to Formatting Text Boxes Office 2019
Novice
Macro to Formatting Text Boxes
 
Join Date: Jun 2021
Posts: 5
effimera is on a distinguished road
Default 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

  • I tried to run a macro for ungrouping them first:

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



  • And then used one that should format all the (ungrouped) text boxes:

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
Reply With Quote
  #2  
Old 06-21-2021, 10:24 PM
Guessed's Avatar
Guessed Guessed is online now Macro to Formatting Text Boxes Windows 10 Macro to Formatting Text Boxes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,648
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

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
Reply With Quote
  #3  
Old 07-01-2021, 01:49 AM
effimera effimera is offline Macro to Formatting Text Boxes Windows 10 Macro to Formatting Text Boxes Office 2019
Novice
Macro to Formatting Text Boxes
 
Join Date: Jun 2021
Posts: 5
effimera is on a distinguished road
Default 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!
Reply With Quote
  #4  
Old 07-01-2021, 03:10 AM
Guessed's Avatar
Guessed Guessed is online now Macro to Formatting Text Boxes Windows 10 Macro to Formatting Text Boxes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,648
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

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
Reply With Quote
Reply

Tags
character spacing, font formatting macro, textboxes

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Formatting Text Boxes 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
Macro to Formatting Text Boxes Drawing lines between text boxes which have actual text within the text boxes RHODIUM Word 6 10-01-2016 04:43 PM
Macro to Formatting Text Boxes 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:26 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft