Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 572|回复: 0

EXEL VBA 判断删除WORD文档页问题

[复制链接]
发表于 2023-6-6 12:32 | 显示全部楼层 |阅读模式
大家好 通过EXCEL VBA 判断删除WORD文档中指定页,但是 下面IF判断立即窗口显示正常但是总是删除不了WORD文档的第2页
不知哪里出现了问题 也没有错误警告

谢谢

Sub BVTEST()
On Error Resume Next
Dim arr
Application.DisplayAlerts = False
Application.ScreenUpdating = False
path = "D:\SM\CIELO ORDER\OB TEST\BV TEST" & "\"
arr = Sheets("OB").Rows(ActiveCell.Row).Rows
Dim wdcx As Object
Dim wd As Object
Set wdcx = CreateObject("word.application")
Set wd = wdcx.Documents.Open(path & "\BV TEST DEMO.docm")
wdcx.Visible = True '显示打开WORD文档
'wdcx.Visible = False '不显示打开WORD文档
    With wdcx
        .ActiveDocument.tables(4).Cell(1, 2).Range.Text = arr(1, 7)
        .ActiveDocument.tables(4).Cell(3, 2).Range.Text = arr(1, 5) & " / " & arr(1, 13)
        .ActiveDocument.tables(4).Cell(3, 4).Range.Text = arr(1, 8)
        .ActiveDocument.tables(4).Cell(5, 2).Range.Text = arr(1, 22)
        .ActiveDocument.tables(4).Cell(6, 2).Range.Text = arr(1, 4) & " " & arr(1, 13)
        .ActiveDocument.tables(5).Cell(1, 1).Range.Text = arr(1, 20) & " TEST"
        .ActiveDocument.tables(5).Cell(2, 1).Range.Text = arr(1, 24)
        .ActiveDocument.tables(6).Cell(1, 2).Range.Text = Date
        .ActiveDocument.tables(8).Cell(1, 2).Range.Text = Date
    End With
'      If wd.ActiveDocument.tables(5).Cell(1, 1).Range.Text = "*PACKAGE TEST*" Then
'            wd.ActiveDocument.Selection.Goto wdGoToPage, wdGoToAbsolute, 2
'            wd.ActiveDocument.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
'            wd.ActiveDocument.Selection.Delete
'            wd.ActiveDocument.Selection.TypeBackspace
'      End If
wd.SaveAs path & arr(1, 4) & " " & arr(1, 5) & " " & arr(1, 13) & " " & arr(1, 22) & " " & arr(1, 20) & " TEST.docx"
wd.Close
wdcx.Quit
Set wdcx = Nothing
Set wd = Nothing
MsgBox arr(1, 4) & " " & arr(1, 5) & " " & arr(1, 13) & " " & arr(1, 22) & " " & arr(1, 20) & " TEST文件已生成"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-28 06:47 , Processed in 0.196708 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表