L
larrysulky
Me again, but different problem.
I have a macro that selects all of the paragraph where the cursor is,
except for the paragraph marker, and copies it into the Word clipboard.
(I know that I could monkey with the "Use smart paragraph selection"
setting, but I get more control over what's happening this way.)
I have another macro that selects the paragraph where the cursor is,
except for the paragraph marker, and pastes the Word clipboard in place
of it (this retains the style of the target paragraph). The macro then
re-applies the current style to remove any locally applied font -- in
other words, it ensures that the font of the target paragraph is what
the style says it should be.
These two macros together let me copy one paragraph over another,
keeping the contents of the source paragraph but the style of the
target paragraph.
Weirdness: If the source paragraph had some italic text in it, that
italicism is lost upon pasting. But if I undo one step, before the
style is re-applied, the italicism is restored. If I then apply the
current style via the Word style interface, the italicism is NOT lost.
Yet the VBA code was created basically by recording a macro of applying
the style via the interface!
Summary: Applying a style to a paragraph via a macro will wipe out
italics (and bold, I reckon) in the paragraph, but doing the same thing
via the Word interface (that was recorded to create the macro in the
first place) will NOT.
Any insights? I need to retain italic, bold, etc., but lose any
"on-a-whim" fonts.
Thanks --
--larry
''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ParaCopy()
On Error GoTo Error_Handler
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Error_Handler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbExclamation, "ParaCopy"
End If
End Sub
Sub ParaPaste()
On Error GoTo Error_Handler
Dim myStyle As String
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Paste
myStyle = Selection.Style
' Selection.MoveLeft Unit:=wdCharacter, Count:=1 ' Doesn't help.
' Selection.MoveRight Unit:=wdCharacter, Count:=1 ' Doesn't help!
' Selection.EndKey Unit:=wdLine ' Jeesh! Doesn't help!!
Selection.Style = ActiveDocument.Styles(myStyle)
Error_Handler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbExclamation, "ParaPaste"
End If
End Sub
I have a macro that selects all of the paragraph where the cursor is,
except for the paragraph marker, and copies it into the Word clipboard.
(I know that I could monkey with the "Use smart paragraph selection"
setting, but I get more control over what's happening this way.)
I have another macro that selects the paragraph where the cursor is,
except for the paragraph marker, and pastes the Word clipboard in place
of it (this retains the style of the target paragraph). The macro then
re-applies the current style to remove any locally applied font -- in
other words, it ensures that the font of the target paragraph is what
the style says it should be.
These two macros together let me copy one paragraph over another,
keeping the contents of the source paragraph but the style of the
target paragraph.
Weirdness: If the source paragraph had some italic text in it, that
italicism is lost upon pasting. But if I undo one step, before the
style is re-applied, the italicism is restored. If I then apply the
current style via the Word style interface, the italicism is NOT lost.
Yet the VBA code was created basically by recording a macro of applying
the style via the interface!
Summary: Applying a style to a paragraph via a macro will wipe out
italics (and bold, I reckon) in the paragraph, but doing the same thing
via the Word interface (that was recorded to create the macro in the
first place) will NOT.
Any insights? I need to retain italic, bold, etc., but lose any
"on-a-whim" fonts.
Thanks --
--larry
''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ParaCopy()
On Error GoTo Error_Handler
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Error_Handler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbExclamation, "ParaCopy"
End If
End Sub
Sub ParaPaste()
On Error GoTo Error_Handler
Dim myStyle As String
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdParagraph, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Paste
myStyle = Selection.Style
' Selection.MoveLeft Unit:=wdCharacter, Count:=1 ' Doesn't help.
' Selection.MoveRight Unit:=wdCharacter, Count:=1 ' Doesn't help!
' Selection.EndKey Unit:=wdLine ' Jeesh! Doesn't help!!
Selection.Style = ActiveDocument.Styles(myStyle)
Error_Handler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbExclamation, "ParaPaste"
End If
End Sub