![]() |
|
#1
|
||||
|
||||
|
Hi, Dear Friends!
I apologize if this has been hashed before. I tried to find it with no success ![]() Word should scan the open doc and wherever it finds a character style named "sty1", it gets the text formatted with that style, cuts it, and pastes it into a text box (frame?) in the margin exactly at the vertical position of the cut text. The text frame should flow so as to keep its connection if any editing is done afterward. ChatGPT has failed on this Thank you Thank you, and have a good day! Susan Flamingo |
|
#2
|
|||
|
|||
|
|
|
#3
|
||||
|
||||
|
Yes, I remember that. Thank you.
But I was looking for a macro that would automate the whole process... |
|
#4
|
|||
|
|||
|
Why use a macro? All you need to do is convert your character style into a paragraph style with a frame, but do a find and replace first to add a paragraph mark after the text formatted with the character style.
|
|
#5
|
|||
|
|||
|
Quote:
First you need to create an appropriate paragraph style for the margin text. You can do that with: Code:
Sub MarginTextStyle()
Dim styleName As String
Dim oStyle As Style
styleName = "Margin Text"
'Create/Setup the style
For Each oStyle In ActiveDocument.Styles
If oStyle.NameLocal = styleName Then GoTo Setup
Next oStyle
ActiveDocument.Styles.Add Name:=styleName, Type:=wdStyleTypeParagraph
Setup:
With ActiveDocument.Styles(styleName)
.AutomaticallyUpdate = False
.BaseStyle = ""
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles(styleName).Font
.Size = 8
.ColorIndex = wdAuto
End With
With ActiveDocument.Styles(styleName).ParagraphFormat
.LineSpacingRule = wdLineSpaceSingle
.SpaceAfter = 0
.WidowControl = False
.KeepWithNext = True
.KeepTogether = True
.OutlineLevel = wdOutlineLevelBodyText
.Shading.BackgroundPatternColor = wdColorLightYellow
With .Borders
.OutsideLineStyle = wdLineStyleSingle
.OutsideLineWidth = wdLineWidth050pt
.OutsideColor = wdColorAutomatic
.DistanceFromTop = 1
.DistanceFromLeft = 1
.DistanceFromBottom = 1
.DistanceFromRight = 1
.Shadow = False
End With
End With
With ActiveDocument.Styles(styleName).Frame
.TextWrap = True
.WidthRule = wdFrameExact
'Accomodate 1" margin. Adjust to suit,
.Width = 55
.HeightRule = wdFrameAuto
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.HorizontalDistanceFromText = InchesToPoints(0.08)
.VerticalDistanceFromText = InchesToPoints(0)
.LockAnchor = False
End With
lbl_Exit:
Exit Sub
End Sub
Then perhaps you could achieve your goal with: Code:
Sub ApplyMarginTextToSty1()
Dim oRng As Range
Dim oRngDef As Range
Dim strDef As String
Set oRng = ActiveDocument.Range
With oRng.Find
.Style = "Sty1"
While .Execute
If oRng.Start = oRng.Paragraphs(1).Range.Start And oRng.End = oRng.Paragraphs(1).Range.End Then
oRng.Style = "Margin Text"
Else
strDef = oRng.Text
oRng.Delete
Set oRngDef = oRng.Paragraphs(1).Range
oRngDef.Start = oRngDef.Paragraphs(1).Range.Start
oRngDef.InsertBefore vbCr
oRngDef.Paragraphs.First.Style = "Margin Text"
oRngDef.Paragraphs.First.Range.Text = strDef
End If
Wend
End With
lbl_Exit:
Exit Sub
End Sub
|
|
#6
|
||||
|
||||
|
Of course, doing this via a macro would not give us any advantage over simply formatting the desired text with the correct style, as in the first answer. But I share the knowledge I learn here with other friends, and some of them couldn't even create a style if their dear life depended on it, so I thought I would use a macro and assign a quick button to it, and walla.
Thank you all And hats off to Greg for again showing there is apparently nothing he cannot do ![]() Thank you, and have a good day! Susan Flamingo |
|
#7
|
|||
|
|||
|
Create a marginal frame. In that, insert a StyleRef Field to your sty1 style.
Then, select your frame and use it to create an AutoText entry (Alt+F3). You can attach a keyboard shortcut to it if you want. AutoComplete will work as well. |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Margin captions (again:( | RRB | Word | 3 | 01-31-2024 03:21 PM |
VBA to insert captions without appending to existing captions
|
Marrick13 | Word VBA | 17 | 03-21-2023 07:51 PM |
| Table captions changing to Figure captions and vice versa | alicatsmom | Word Tables | 0 | 06-11-2019 08:51 AM |
Some captions getting screwed up when fixing other captions
|
oliboi | Word | 2 | 08-30-2016 02:55 PM |
Captions: Changing captions in Appendix update all captions
|
carnestw | Word | 3 | 10-27-2015 12:34 PM |