Vb.net 如何从word文档中删除特定页面
我使用的是Vb.net 如何从word文档中删除特定页面,vb.net,ms-word,Vb.net,Ms Word,我使用的是vb.net,我正在编辑一个word文档 我只想删除从第6页(例如)到文档末尾的分页符,而不是从整个文档中删除 我的代码是针对整个文档的-我应该如何更改它 Dim paragraphs As Word.Paragraphs paragraphs = doc.Paragraphs For Each paragraph As Word.Paragraph In paragraphs If paragraph.Range.Text.Trim() = String.Empty The
vb.net
,我正在编辑一个word文档
我只想删除从第6页(例如)到文档末尾的分页符,而不是从整个文档中删除
我的代码是针对整个文档的-我应该如何更改它
Dim paragraphs As Word.Paragraphs
paragraphs = doc.Paragraphs
For Each paragraph As Word.Paragraph In paragraphs
If paragraph.Range.Text.Trim() = String.Empty Then
paragraph.Range.[Select]()
wordapp.Selection.Delete()
End If
Next
这对我有用。这将从第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
以上代码经过测试和尝试:)您是否将此行的页码设置为Integer=6是,但问题是我需要从第6页到文档末尾。我尝试这样做但没有成功:将doc For i=.parations.Count设置为1步-1如果(Asc(.parations(i).Range.Text)=12和(.parations(i).Range.Information(Word.WdInformation.wdActiveEndPageNumber)>PageNumberToStart))然后.段落(i).Range.Delete()结束,如果下一步我以OH结束,则修改循环中的代码。将
=pgNo
更改为=pgNo
。一切照旧