欢迎访问抖客教程网!

抖客教程网

您现在的位置是:主页 > 办公课堂 > Word教程 > Word技巧大全 >

Word技巧大全

VB如对OLE控件中的word内容举办替换

发布时间:2024-05-25 03:00:01Word技巧大全评论
1.VB如对OLE控件中的word内容举办替换 曾经做过些。 复制下来给你参考我是从XML里读到数据往Word内里替换数据的。建造一个Word模板,内里可变的内容用{$TITLE}取代{$TITLE} Dim wordApp As Wor

1.VB如对OLE控件中的word内容举办替换

曾经做过些。

复制下来给你参考我是从XML里读到数据往Word内里替换数据的。建造一个Word模板,内里可变的内容用{$TITLE}取代{$TITLE} Dim wordApp As Word.Application Set wordApp = New Word.Application wordApp.Visible = False Dim wordSelection As Word.Selection Dim objDoc As Word.Document Set objDoc = wordApp.Documents.Open("template.doc") Set wordSelection = wordApp.SelectionReplaceChar "{$TITLE}", xmlNode.Text If xmlNodes.Length > 1 Then objDoc.Tables(1).Select Selection.InsertRowsBelow xmlNodes.Length - 1 End If'美化Word文件:去除去反复的段落标志。

Public Sub ReduceParagraph() '必需写为wordApp.Selection wordApp.Selection.Find.ClearFormatting wordApp.Selection.Find.Replacement.ClearFormatting With wordApp.Selection.Find .Text = "^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With wordApp.Selection.Find.Execute Replace:=wdReplaceAllEnd Sub'直接将全部匹配的标签替换为功效文本。Public Sub ReplaceChar(ReplacedStr As String, ReplacementStr As String) Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = ReplacedStr .Replacement.Text = ReplacementStr .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 'Selection.TypeText Text:=ReplacementStrEnd Sub'从前往后,查找图片标签,然后直接插入图片,图片文件可以当地全路径可能Web全路径。

Public Sub ReplaceImg(ReplacedStr As String, ReplacementStr As String) Selection.Find.ClearFormatting With Selection.Find .Text = ReplacedStr .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=1 Selection.InlineShapes.AddPicture fileName:= _ ReplacementStr, LinkToFile:=False, _ SaveWithDocument:=TrueEnd Sub。

2.VB如对OLE控件中的word内容举办替换

曾经做过些。

复制下来给你参考 我是从XML里读到数据往Word内里替换数据的。建造一个Word模板,内里可变的内容用{$TITLE}取代 {$TITLE} Dim wordApp As Word.Application Set wordApp = New Word.Application wordApp.Visible = False Dim wordSelection As Word.Selection Dim objDoc As Word.Document Set objDoc = wordApp.Documents.Open("template.doc") Set wordSelection = wordApp.Selection ReplaceChar "{$TITLE}", xmlNode.Text If xmlNodes.Length > 1 Then objDoc.Tables(1).Select Selection.InsertRowsBelow xmlNodes.Length - 1 End If'美化Word文件:去除去反复的段落标志。

Public Sub ReduceParagraph() '必需写为wordApp.Selection wordApp.Selection.Find.ClearFormatting wordApp.Selection.Find.Replacement.ClearFormatting With wordApp.Selection.Find .Text = "^p^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With wordApp.Selection.Find.Execute Replace:=wdReplaceAll End Sub'直接将全部匹配的标签替换为功效文本。Public Sub ReplaceChar(ReplacedStr As String, ReplacementStr As String) Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = ReplacedStr .Replacement.Text = ReplacementStr .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 'Selection.TypeText Text:=ReplacementStr End Sub'从前往后,抖客教程网,查找图片标签,然后直接插入图片,图片文件可以当地全路径可能Web全路径。

Public Sub ReplaceImg(ReplacedStr As String, ReplacementStr As String) Selection.Find.ClearFormatting With Selection.Find .Text = ReplacedStr .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=1 Selection.InlineShapes.AddPicture fileName:= _ ReplacementStr, LinkToFile:=False, _ SaveWithDocument:=True End Sub。

热心评论

评论列表