如何从word文档中删除特定页面

时间:2015-05-18 10:32:20

标签: vb.net ms-word

我正在使用<div class="container"> <a href="#" class="href1"></a> <a href="#" class="href2"></a> </div .href1, .href2 { display:block; width:100px; height:100px; } .href1 { background:red; border:2px solid #000; margin-bottom:30px; } .href1:hover { border-color:yellow; } .href2 { background:blue; } .href2:hover .href1 { border-color:yellow; } ,我有一个我正在编辑的word文档。

我想仅从第6页(例如)到文档末尾而不是整个文档中删除分页符。

我的代码是整个文档 - 我该如何更改?

vb.net

1 个答案:

答案 0 :(得分:1)

这对我有用。这将从第6页删除分页符(如果存在)。

Imports Word = Microsoft.Office.Interop.Word

Public Class Form1

    '~~> Define your Excel Objects
    Dim wrdApp As New Word.Application
    Dim wrdDoc As Word.Document
    '~~> Page NO
    Dim pgNo As Integer = 6
    Dim i As Integer = 0

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        wrdDoc = wrdApp.Documents.Open("C:\Users\Siddharth\Desktop\Document1.docx")

        '~~> Display Word
        wrdApp.Visible = True

        With wrdDoc
            For i = .Paragraphs.Count To 1 Step -1
                If Asc(.Paragraphs(i).Range.Text) = 12 And _
                   .Paragraphs(i).Range.Information(Word.WdInformation.wdActiveEndPageNumber) = pgNo Then
                    .Paragraphs(i).Range.Delete()
                    Exit For
                End If
            Next i
        End With
    End Sub
End Class