首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Excel VBA删除Word文档中的水印

使用Excel VBA删除Word文档中的水印
EN

Stack Overflow用户
提问于 2017-03-11 01:07:24
回答 1查看 718关注 0票数 0

我正在尝试使用excel删除word文档中所有区域的水印。我可以在Word中用VB完成这项工作,我已经将代码翻译到excel中,以便在word中完成。没有错误,但代码无法删除或移除水印。我相信一定有一些额外的链接到它的形状或位置,我需要参考,但我不知道它会丢失什么。

Word VBA中的工作代码使用了spShape.Visible = False,这在excel中没有做任何事情,我也尝试过spShape.Delete,但也没有用。

感谢任何帮助,以下是我的代码:

代码语言:javascript
运行
复制
Sub AddRemoveWatermark()
'Word Variables
Dim wrdApplication As Word.Application
Dim wrdDocument As Word.Document
Dim wrdSection As Word.section
Dim wrdHeader As Word.HeaderFooter
Dim rngHeader As Word.Range
Dim spShape As Word.Shape

Dim strDocumentName As String
Dim strPath As String
Dim strBBPath As String
Dim lngCount As Long
Dim pHeaderType As Long
Dim strShapeName As String

' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = True
    .Show

    Set wrdApplication = New Word.Application

    ' Display paths of each file selected
    For lngCount = 1 To .SelectedItems.Count
        strPath = .SelectedItems(lngCount)
        Set wrdDocument = wrdApplication.Documents.Open(strPath)

        strDocumentName = wrdDocument.FullName 'Record the document name
        wrdApplication.Templates.LoadBuildingBlocks

        wrdApplication.Visible = True

            'Address each section
            For Each wrdSection In wrdDocument.Sections
                With wrdSection
                    Set rngHeader = .Headers(wdHeaderFooterFirstPage).Range
                    For Each spShape In rngHeader.ShapeRange
                        strShapeName = spShape.Name

                        If InStr(strShapeName, "PowerPlusWaterMarkObject") > 0 Then
                            'spShape.Delete
                            spShape.Visible = msoFalse
                        End If
                    Next

                    Set rngHeader = .Headers(wdHeaderFooterPrimary).Range

                    For Each spShape In rngHeader.ShapeRange
                        strShapeName = spShape.Name

                        If InStr(strShapeName, "PowerPlusWaterMarkObject") > 0 Then
                            'spShape.Delete
                            spShape.Visible = msoFalse
                        End If
                    Next

                End With
            Next wrdSection

            wrdDocument.SaveAs (wrdDocument.FullName)

        wrdDocument.Close
    Next lngCount
End With

wrdApplication.Quit

End Sub
EN

Stack Overflow用户

发布于 2020-08-23 20:30:52

嘿是我用来去除水印的代码,虽然不是很优雅。

代码语言:javascript
运行
复制
Sub RemoveWordArtWaterMark()
'on error resume next
On Error Resume Next
'from google group
Dim x           As Long
For x = 1 To 20
    ActiveDocument.sections(1).Headers(wdHeaderFooterFirstPage).Shapes(1).Delete
Next x

结束子对象

票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42723964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档