WordProcessingML使用VBA应用程序清理 [英] WordProcessingML Clean Using VBA Application

查看:96
本文介绍了WordProcessingML使用VBA应用程序清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

我正在使用WordML + VBA申请

这是示例WordML文件

< ?xml version =" 1.0" standalone =" yes"?>
<?mso-application progid =" Word.Document"?>
< w:wordDocument xmlns:w =" http://schemas.microsoft.com/office/word/2003/wordml "的xmlns:V ="瓮:架构 - 微软-COM:VML"的xmlns:W10 = QUOT;瓮:架构 - 微软-COM:办公室:单词QUOT; xmlns:sl =" http://schemas.microsoft.com/schemaLibrary/2003/core " xmlns:aml =" http://schemas.microsoft.com/aml/2001/core " xmlns:wx =" http://schemas.microsoft.com/office/word/2003/auxHint"的xmlns:○= QUOT;瓮:架构 - 微软-COM:办公室:办公室"的xmlns:DT = QUOT; UUID:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:wsp =" http://schemas.microsoft.com/office/word/2003/wordml/ SP2 "瓦特:macrosPresent = QUOT;否]瓦特:embeddedObjPresent = QUOT;否]瓦特:ocxPresent = QUOT;否] xml:space =" preserve">
< w:ignoreElements w:val =" http://schemas.microsoft.com/office/word/2003/wordml/sp2"/ >
<○:DocumentProperties>
<○:版> 11.0000< / o:版本>
< / o:DocumentProperties>
< w:fonts>
< w:defaultFonts w:ascii =" Times New Roman" w:fareast =" Times New Roman" w:h-ansi =" Times New Roman" w:cs =" Times New Roman" />
< / w:fonts>
< w:styles>
< w:versionOfBuiltInStylenames w:val =" 4" ; />
< w:latentStyles w:defLockedState =" off" w:latentStyleCount =" 156" />
< w:style w:type =" paragraph"瓦特:默认= QUOT在...上QUOT; w:styleId =" Normal">
< w:name w:val =" Normal" />
< w:rPr>
< wx:font wx :val =" Times New Roman" />
< w:sz w:val =" 24" />
< w:sz-cs w:val =" 24" ;>
< w:lang w:val =" EN-US"瓦特:远东= QUOT; EN-US" w:bidi =" AR-SA" />
< / w:rPr>
< / w:style>
< w:style w:type ="段" w:styleId =" Heading1">
< w:name w:val =" heading 1" />
< wx:uiName wx:val =" Heading 1" / >
< w:basedOn w:val =" Normal" />
< w:next w:val =" Normal" />
< w: rsid w:val =" 003A666D" />
< w:pPr>
< w:pStyle w:val =" Heading1" />
< w: keepNext />
< w:spacing w:before =" 240" w:after =" 60" />
< w:outlineLvl w:val =" 0" />
< / w:pPr>
< w: rPr>
< w:rFonts w:ascii =" Arial"瓦特:H-ANSI = QUOT; Arial字体" w:cs =" Arial" />
< wx:font wx:val =" Arial" />
< w:b />
< w :b-cs />
< w:kern w:val =" 32" />
< w:sz w:val =" 32" />
< w:sz-cs w:val =" 32" />
< / w:rPr>
< / w:style>
< w:style瓦特:类型= QUOT;段" w:styleId =" Heading2">
< w:name w:val =" heading 2" />
< wx:uiName wx:val =" Heading 2" / >
< w:basedOn w:val =" Normal" />
< w:next w:val =" Normal" />
< w: rsid w:val =" 003A666D" />
< w:pPr>
< w:pStyle w:val =" Heading2" />
< w: keepNext />
< w:spacing w:before =" 240" w:after =" 60" />
< w:outlineLvl w:val =" 1" />
< / w:pPr>
< w: rPr>
< w:rFonts w:ascii =" Arial"瓦特:H-ANSI = QUOT; Arial字体" w:cs =" Arial" />
< wx:font wx:val =" Arial" />
< w:b />
< w :b-cs />
< w:i />
< w:i-cs />< w:sz w:val =" 28" />
< w:sz-cs w:val =" 28" />
< / w:rPr>
< / w:style>
< w:style w:type =" paragraph" w:styleId =" Heading3">
< w:name w:val =" heading 3" />
< wx:uiName wx:val =" Heading 3" / >
< w:basedOn w:val =" Normal" />
< w:next w:val =" Normal" />
< w: rsid w:val =" 00186666" />
< w:pPr>
< w:pStyle w:val =" Heading3" />
< w: keepNext />
< w:spacing w:before =" 240" w:after =" 60" />
< w:outlineLvl w:val =" 2" />
< / w:pPr>
< w: rPr>
< w:rFonts w:ascii =" Arial"瓦特:H-ANSI = QUOT; Arial字体" w:cs =" Arial" />
< wx:font wx:val =" Arial" />
< w:b />
< w :b-cs />
< w:sz w:val =" 26" />
< w:sz-cs w:val =" 26" /> < br&>< / w:rPr>
< / w:style>
< w:style w:type =" character"瓦特:默认= QUOT在...上QUOT; w:styleId =" DefaultParagraphFont">
< w:name w:val =" Default Paragraph Font" />
< w:semiHidden />
< / w:style>
< w:style w:type =" table"瓦特:默认= QUOT在...上QUOT; w:styleId =" TableNormal">
< w:name w:val =" Normal Table" />
< wx:uiName wx:val =" Table Normal" / >
< w:semiHidden />
< w:rPr>
< wx:font wx:val =" Times New Roman" />
< / w:rPr>
< w:tblPr>
< w:tblInd w:w =" 0" w:type =" dxa" />
< w:tblCellMar>
< w:top w:w =" 0" w:type =" dxa" />
< w:left w:w =" 108" w:type =" dxa" />
< w:bottom w:w =" 0" w:type =" dxa" />
< w:right w:w =" 108"瓦特:类型= QUOT; DXA" />
< / W:tblCellMar>
< / W:tblPr>
< / W:式>
< w:style w:type =" list"瓦特:默认= QUOT在...上QUOT; w:styleId =" NoList">
< w:name w:val =" No List" />
< w:semiHidden />
< / w:style>
< w:style w:type =" table" w:styleId =" TableGrid">
< w:name w:val =" Table Grid" />
< w:basedOn w:val =" TableNormal" /> ;< w:rsid w:val =" 003A666D" />
< w:rPr>
< wx:font wx:val =" Times New Roman" />
< / w:rPr>
< w:tblPr>
< w:tblInd w:w =" 0" w:type =" dxa" />
< w:tblBorders>
< w:top w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< w:left w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< w:bottom w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< w:right w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< w:insideH w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< w:insideV w:val =" single"瓦特:SZ = QUOT; 4英寸WX:bdrwidth = QUOT; 10"瓦特:空间= QUOT; 0" w:color =" auto" />
< / w:tblBorders>
< w:tblCellMar>< w:top w:w =" 0" w:type =" dxa" />
< w:left w:w =" 108" w:type =" dxa" />
< w:bottom w:w =" 0" w:type =" dxa" />
< w:right w:w =" 108"瓦特:类型= QUOT; DXA" />
< / W:tblCellMar>
< / W:tblPr>
< / W:式>
< / w:styles>
< w:docPr>
< w:view w:val =" normal" />
< w:zoom w:percent =" 100" />
< w:doNotEmbedSystemFonts />
< w:attachedTemplate w:val ="" />
< w:defaultTabStop w:val = " 720">
< w:punctuationKerning />
< w:characterSpacingControl w:val =" DontCompress" />
< w:optimizeForBrowser /> ;< w:validateAgainstSchema />
< w:saveInvalidXML w:val =" off" />
< w:ignoreMixedContent w:val =" off" />
< w:alwaysShowPlaceholderText w:val =" off" />
< w:compat>
< w:breakWrappedTables />
< ; W:snapToGridInCell />
< W:wrapTextWithPunct />
< W:useAsianBreakRules />
< W:dontGrowAutofit /& gt;
< / w:compat>
< wsp:rsids>
< wsp:rsidRoot wsp:val =" 003A666D" />
< wsp :rsid wsp:val =" 00186666" />
< wsp:rsid wsp:val =" 003A666D" />
< wsp:rsid wsp:val =" 004274B0" />
< wsp:rsid wsp:val =" 00930EFE" />
< wsp:rsid wsp:val =" 00AA0508" />
< / wsp:rsids>
< / w:docPr>
< w:body>
< wx:sect>
< w:p wsp:rsidR =" 00000000 QUOT; wsp:rsidRDefault =" 00930EFE" />
< w:sectPr wsp:rsidR =" 00000000">< w:pgSz w:w =" 12240" w:h =" 15840" />
< w:pgMar w:top =" 1440"瓦特:右= QUOT; 1800"瓦特:底部= QUOT; 1440"瓦特:左= QUOT; 1800"瓦特:头= QUOT; 720"瓦特:页脚= QUOT; 720" w:gutter =" 0">
< w:cols w:space =" 720" />
< / w:sectPr>
< / wx :sect>
< / w:body>
< / w:wordDocument>


Hi All

I am working WordML + VBA Application

This is Sample WordML File

<?xml version="1.0" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
 <w:ignoreElements w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2"/>
 <o:DocumentProperties>
  <o:Version>11.0000</o:Version>
 </o:DocumentProperties>
 <w:fonts>
  <w:defaultFonts w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman"/>
 </w:fonts>
 <w:styles>
  <w:versionOfBuiltInStylenames w:val="4"/>
  <w:latentStyles w:defLockedState="off" w:latentStyleCount="156"/>
  <w:style w:type="paragraph" w:default="on" w:styleId="Normal">
   <w:name w:val="Normal"/>
   <w:rPr>
    <wx:font wx:val="Times New Roman"/>
    <w:sz w:val="24"/>
    <w:sz-cs w:val="24"/>
    <w:lang w:val="EN-US" w:fareast="EN-US" w:bidi="AR-SA"/>
   </w:rPr>
  </w:style>
  <w:style w:type="paragraph" w:styleId="Heading1">
   <w:name w:val="heading 1"/>
   <wx:uiName wx:val="Heading 1"/>
   <w:basedOn w:val="Normal"/>
   <w:next w:val="Normal"/>
   <w:rsid w:val="003A666D"/>
   <w:pPr>
    <w:pStyle w:val="Heading1"/>
    <w:keepNext/>
    <w:spacing w:before="240" w:after="60"/>
    <w:outlineLvl w:val="0"/>
   </w:pPr>
   <w:rPr>
    <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
    <wx:font wx:val="Arial"/>
    <w:b/>
    <w:b-cs/>
    <w:kern w:val="32"/>
    <w:sz w:val="32"/>
    <w:sz-cs w:val="32"/>
   </w:rPr>
  </w:style>
  <w:style w:type="paragraph" w:styleId="Heading2">
   <w:name w:val="heading 2"/>
   <wx:uiName wx:val="Heading 2"/>
   <w:basedOn w:val="Normal"/>
   <w:next w:val="Normal"/>
   <w:rsid w:val="003A666D"/>
   <w:pPr>
    <w:pStyle w:val="Heading2"/>
    <w:keepNext/>
    <w:spacing w:before="240" w:after="60"/>
    <w:outlineLvl w:val="1"/>
   </w:pPr>
   <w:rPr>
    <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
    <wx:font wx:val="Arial"/>
    <w:b/>
    <w:b-cs/>
    <w:i/>
    <w:i-cs/>
    <w:sz w:val="28"/>
    <w:sz-cs w:val="28"/>
   </w:rPr>
  </w:style>
  <w:style w:type="paragraph" w:styleId="Heading3">
   <w:name w:val="heading 3"/>
   <wx:uiName wx:val="Heading 3"/>
   <w:basedOn w:val="Normal"/>
   <w:next w:val="Normal"/>
   <w:rsid w:val="00186666"/>
   <w:pPr>
    <w:pStyle w:val="Heading3"/>
    <w:keepNext/>
    <w:spacing w:before="240" w:after="60"/>
    <w:outlineLvl w:val="2"/>
   </w:pPr>
   <w:rPr>
    <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
    <wx:font wx:val="Arial"/>
    <w:b/>
    <w:b-cs/>
    <w:sz w:val="26"/>
    <w:sz-cs w:val="26"/>
   </w:rPr>
  </w:style>
  <w:style w:type="character" w:default="on" w:styleId="DefaultParagraphFont">
   <w:name w:val="Default Paragraph Font"/>
   <w:semiHidden/>
  </w:style>
  <w:style w:type="table" w:default="on" w:styleId="TableNormal">
   <w:name w:val="Normal Table"/>
   <wx:uiName wx:val="Table Normal"/>
   <w:semiHidden/>
   <w:rPr>
    <wx:font wx:val="Times New Roman"/>
   </w:rPr>
   <w:tblPr>
    <w:tblInd w:w="0" w:type="dxa"/>
    <w:tblCellMar>
     <w:top w:w="0" w:type="dxa"/>
     <w:left w:w="108" w:type="dxa"/>
     <w:bottom w:w="0" w:type="dxa"/>
     <w:right w:w="108" w:type="dxa"/>
    </w:tblCellMar>
   </w:tblPr>
  </w:style>
  <w:style w:type="list" w:default="on" w:styleId="NoList">
   <w:name w:val="No List"/>
   <w:semiHidden/>
  </w:style>
  <w:style w:type="table" w:styleId="TableGrid">
   <w:name w:val="Table Grid"/>
   <w:basedOn w:val="TableNormal"/>
   <w:rsid w:val="003A666D"/>
   <w:rPr>
    <wx:font wx:val="Times New Roman"/>
   </w:rPr>
   <w:tblPr>
    <w:tblInd w:w="0" w:type="dxa"/>
    <w:tblBorders>
     <w:top w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
     <w:left w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
     <w:bottom w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
     <w:right w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
     <w:insideH w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
     <w:insideV w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
    </w:tblBorders>
    <w:tblCellMar>
     <w:top w:w="0" w:type="dxa"/>
     <w:left w:w="108" w:type="dxa"/>
     <w:bottom w:w="0" w:type="dxa"/>
     <w:right w:w="108" w:type="dxa"/>
    </w:tblCellMar>
   </w:tblPr>
  </w:style>
 </w:styles>
 <w:docPr>
  <w:view w:val="normal"/>
  <w:zoom w:percent="100"/>
  <w:doNotEmbedSystemFonts/>
  <w:attachedTemplate w:val=""/>
  <w:defaultTabStop w:val="720"/>
  <w:punctuationKerning/>
  <w:characterSpacingControl w:val="DontCompress"/>
  <w:optimizeForBrowser/>
  <w:validateAgainstSchema/>
  <w:saveInvalidXML w:val="off"/>
  <w:ignoreMixedContent w:val="off"/>
  <w:alwaysShowPlaceholderText w:val="off"/>
  <w:compat>
   <w:breakWrappedTables/>
   <w:snapToGridInCell/>
   <w:wrapTextWithPunct/>
   <w:useAsianBreakRules/>
   <w:dontGrowAutofit/>
  </w:compat>
  <wsp:rsids>
   <wsp:rsidRoot wsp:val="003A666D"/>
   <wsp:rsid wsp:val="00186666"/>
   <wsp:rsid wsp:val="003A666D"/>
   <wsp:rsid wsp:val="004274B0"/>
   <wsp:rsid wsp:val="00930EFE"/>
   <wsp:rsid wsp:val="00AA0508"/>
  </wsp:rsids>
 </w:docPr>
 <w:body>
  <wx:sect>
   <w:p wsp:rsidR="00000000" wsp:rsidRDefault="00930EFE"/>
   <w:sectPr wsp:rsidR="00000000">
    <w:pgSz w:w="12240" w:h="15840"/>
    <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0"/>
    <w:cols w:space="720"/>
   </w:sectPr>
  </wx:sect>
 </w:body>
</w:wordDocument>

此Word文档具有"HELLO WORD"字样。具有不同风格的文字,Bold,Italics&下划线

问题我需要清理WordML以删除所有样式,包括粗体斜体和&在清理WordML之后强调"HELLO WORD"测试应该是正常的

我已经尝试过编写XSLT进行清理过程而且我也尝试了Micrsoft Office Inferecne工具,事情没有用完了

我需要在VBA中编写一个函数来清理WordML并保留所有样式粗体,斜体和下划线

任何有任何解决方案和建议都可以分享您的体验

作为Orcas .King

This Word Document has "HELLO WORD" text which has different styles, Bold , Italics & Underline

Problem i need to clean up the WordML to remove the all the styles , Including bold italics & underline after clean up the WordML The "HELLO WORD" test should be in normal

I have tried writing the XSLT to clean process and i have also tried the Micrsoft Office Inferecne tool, thing doesn't work out

I need to write an Function in VBA to cleanup the WordML and retain all the styles bold , italics and underline

any have any solution and suggestion kindly share your experience


Orcas.King

推荐答案

你好朋友,

请通过以下功能,它将有助于您的查询。

如果您对此有更多疑问,请告诉我。谢谢&祝福。祝你有个选择。对于使用此功能,您需要设置Microsoft XML,Versino 2.0的参考:
'位置是:C:\ windows \ system32 \msxml.dll
'方法ReplaceFormattingFromWordML'
'用于替换Word XML文件中的格式....
'在此函数中有四个参数使用,参数详情如下左'(1)m_SourcePath As String ---应用你需要删除格式的源文字ML文件的路径
'(2)m_DestinationPath As字符串---应用目的地的路径Word ML文件
'(3)m_SearchWord作为字符串,---应用您需要在Word ML中搜索的搜索字符串并删除它的格式样式。
' (4)ModeOfComparition作为VbCompareMethod ---应用适当的比较模式--- vbTextCompare模式是最好的,它不区分大小写,对于区分大小写的搜索应用vbBinaryCompare
'如果需要进一步的细节,请问我:) />
子测试()
'

'
ReplaceFormattingFromWordML" C:\ Work Station \ Access Group \ Word \ WordML \ FormattedWordML.xml"," C:\\ \\ WORK Station \AccessGroup \Word \WordML \ NewWordML.xml","Hello World",vbTextCompare
''


结束子

Sub ReplaceFormattingFromWordML(m_SourcePath As String,m_DestinationPath As String,m_SearchWord As String,ModeOfComparition As VbCompareMethod)
''Dim iDoc As New MSXML.DOMDocument
Dim iNodeList As MSXML.IXMLDOMNodeList
Dim iNode As MSXML.IXMLDOMNode
Dim iNodeToRemove As MSXML.IXMLDOMNode
'''''''''''''''''''''''''''''' (m_SourcePath)
''''''''''''''''''设置iNodeList = iDoc.SelectNodes(" // w:body / wx:sect / w :p")
对于iNodeList中的每个iNode

Debug.Print iNode.XML

如果不是iNode.SelectSingleNode(" w:r / w:t")什么都没有那么就是''''''''' '''''''''''''如果是InStr(1,iNode.SelectSingleNode(" w:r / w:t")。Text,m_SearchWord,vbTextCompare)> 0然后是'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ;)
iNode.SelectSingleNode(" w:r")。RemoveChild iNode.SelectSingleNode(" w:r / w:rPr")
''''''''''' ''''''''结束如果是''''''''''''''结束如果
下一个
'''''''''''''iDoc.Save m_DestinationPath
'''''''''''''''''''''''''''''' '终止子


这篇关于WordProcessingML使用VBA应用程序清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆