从多个文件中删除图片(Microsoft Word)
罗萨里奥(Rosario)有大量文档(其中约有44,000个),每个文档的标题中都有一个图形。她正在寻找一种删除所有这些图形的方法,而无需手动打开和修改每个文档。
幸运的是,可以通过创建宏来处理。您需要做的就是将所有文档放在一个文件夹中,然后使用宏在文件夹中搜索,打开每个文档,删除图形并保存每个文档。可以使用如下宏来完成:
Sub StripGraphics() Dim oShape As Shape Dim oIShape As InlineShape Dim I As Integer Dim J As Integer With Application.FileSearch .LookIn = "C:\MyStuff\" ' where to search .SearchSubFolders = True ' search the subfolders .FileName = "*.doc" ' file pattern to match ' if more than one match, execute the following code If .Execute() > 0 Then MsgBox "Found " & .FoundFiles.Count & " file(s)." ' for each file you find, run this loop For I = 1 To .FoundFiles.Count ' open the file based on its index position Documents.Open FileName:=.FoundFiles(I) ' document is now active, check all sections For J = 1 To ActiveDocument.Sections.Count With ActiveDocument.Sections(J).Headers(wdHeaderFooterPrimary) ' remove floating graphics from header If .Shapes.Count > 0 Then For Each oShape In .Shapes oShape.Delete Next oShape End If ' remove inline graphics from header If .Range.InlineShapes.Count > 0 Then For Each oIShape In .Range.InlineShapes oIShape.Delete Next oIShape End If End With With ActiveDocument.Sections(J).Headers(wdHeaderFooterFirstPage) ' remove floating graphics from header If .Shapes.Count > 0 Then For Each oShape In .Shapes oShape.Delete Next oShape End If ' remove inline graphics from header If .Range.InlineShapes.Count > 0 Then For Each oIShape In .Range.InlineShapes oIShape.Delete Next oIShape End If End With Next J ' save and close the current document ActiveDocument.Close wdSaveChanges Next I Else MsgBox "No files found." End If End With End Sub
该宏假定您要删除标题中的所有图形(浮动图形和嵌入式图形)。这些将被删除,并且每个文件都将被保存。该宏不会影响文档中的任何其他图形。
注意:
如果您想知道如何使用此页面(或_WordTips_网站上的任何其他页面)中描述的宏,我准备了一个包含有用信息的特殊页面。
_WordTips_是您进行经济有效的Microsoft Word培训的来源。
(Microsoft Word是世界上最流行的文字处理软件。)本技巧(311)适用于Microsoft Word 97、2000、2002和2003。您可以为Word(Word 2007)的功能区界面找到此技巧的版本。和更高版本)在这里: