Rakesh
05-01-2011, 09:57 AM
Hi Rocks,
I have the following code to insert some text at the beginning of the para based on the stylesheet naming. But it shows an error when the document does not used the stylesheet which is mentioned in the Coding.
Sub aa()
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("SOI_P_H1")
.Text = "([!^13]@[^13])"
.Replacement.Text = "@SI-major entry hd:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("SOI_P_H2")
.Text = "([!^13]@[^13])"
.Replacement.Text = "@SI-minor entry hd ko:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV1")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level2:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV2")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level3:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV3")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level4:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_STACK")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Stack:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
How to fix it?
Herewith I have attached sample doc to run the coding.
Thanks,
Rakesh
I have the following code to insert some text at the beginning of the para based on the stylesheet naming. But it shows an error when the document does not used the stylesheet which is mentioned in the Coding.
Sub aa()
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("SOI_P_H1")
.Text = "([!^13]@[^13])"
.Replacement.Text = "@SI-major entry hd:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Style = ActiveDocument.Styles("SOI_P_H2")
.Text = "([!^13]@[^13])"
.Replacement.Text = "@SI-minor entry hd ko:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV1")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level2:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV2")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level3:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_LEV3")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Level4:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content.Find
.Style = ActiveDocument.Styles("SOI_P_STACK")
.Text = "([!^13]@[^13])"
.Replacement.Text = "Stack:\1"
.Forward = True
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
How to fix it?
Herewith I have attached sample doc to run the coding.
Thanks,
Rakesh