Excel VBA删除Word中的空行

时间:2018-10-18 09:24:56

标签: excel vba ms-word

因为我确实在Word中从Excel VBA中找到了'n replace,所以我必须在Word中删除空白/空行。

这是我当前的代码:

Sub xyz()

Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdRng As Word.Range

Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(Cur_dir_var & "\!Automatisering gegevens template.docx")
For Each wdRng In wdDoc.StoryRanges



'~~> Find 'n replace
With wdRng.Find
                .Text = "<Project naam>"
                .Replacement.Text = Project_naam_var
                .Wrap = wdFindContinue
                .Execute Replace:=wdReplaceAll

                .Text = "<Klant>"
                .Replacement.Text = Klant_var
                .Wrap = wdFindContinue
                .Execute Replace:=wdReplaceAll
End With

Next wdRng

'~~> Save as
wdDoc.SaveAs2 Filename:=Cur_dir_var & "\" & Worksheets("Algemeen").Range("B3").Value & " Automatisering gegevens.docx"

'~~> Quit
    wdApp.Quit

'~~> Clean up
Set wdApp = Nothing: Set wdDoc = Nothing: Set wdRng = Nothing
End Sub

我想删除Word文档中的所有空行。如何才能做到最好,并将其实现到当前代码中?

提前谢谢!

示例:

<netwerk1_naam_var>
<netwerk1_merk_var>
<netwerk1_type_var>
<netwerk1_ip_var>
<netwerk1_subnet_var>
<netwerk1_Username_var>
<netwerk1_Password_var>
<netwerk1_MAC_var>
<ENTER>
<netwerk2_naam_var>
<netwerk2_merk_var>
<netwerk2_type_var>
<netwerk2_ip_var>
<netwerk2_subnet_var>
<netwerk2_Username_var>
<netwerk2_Password_var>
<netwerk2_MAC_var>
<ENTER>

0 个答案:

没有答案
相关问题