falconwing
10-12-2007, 11:41 AM
In a word 2003 document, the user invokes my macro anywhere inside the document. The macro then injects text with normal style. After it is finished, the macro should set the text attributes back to what they where before the text was injected.
Dim saveStyle As String
Dim saveFont As Object
...
saveStyle = Selection.Style
Set saveFont = Selection.Font
...
'code injects text here
....
'now ready to put text attributes back as they were
Selection.Style = saveStyle
Set Selection.Font = saveFont
So the problem is that the last line of code fails ("Run-time error '438': Object doesn't support this property of method").
I have also tried making saveFont type Font, but that also does not work. When I look at Selection.Font and saveFont in the variables windows they are both object/Font and have the same data. I'd prefer some elegant way to do this rather than discretely setting every text attribute, although if there was a way to foreach through them programmatically that would be bearable.
Just saving and restoring the style has not been sufficient as it does not pick up font changes on an existing style.
I do not want to
with Selection.Font
.Bold = saveFont.Bold
.Name = saveFont.Name
.Size = saveFont.Size
... etc may times over ...
end with
Any insights greatly appreciated...
Falconwing
Dim saveStyle As String
Dim saveFont As Object
...
saveStyle = Selection.Style
Set saveFont = Selection.Font
...
'code injects text here
....
'now ready to put text attributes back as they were
Selection.Style = saveStyle
Set Selection.Font = saveFont
So the problem is that the last line of code fails ("Run-time error '438': Object doesn't support this property of method").
I have also tried making saveFont type Font, but that also does not work. When I look at Selection.Font and saveFont in the variables windows they are both object/Font and have the same data. I'd prefer some elegant way to do this rather than discretely setting every text attribute, although if there was a way to foreach through them programmatically that would be bearable.
Just saving and restoring the style has not been sufficient as it does not pick up font changes on an existing style.
I do not want to
with Selection.Font
.Bold = saveFont.Bold
.Name = saveFont.Name
.Size = saveFont.Size
... etc may times over ...
end with
Any insights greatly appreciated...
Falconwing