VBA if 后不能执行msgbox

flythink 2006-12-06 03:32:12
Word 文件的第一行的第三个字符为空,所以ThisDocument.Words.Item(2) Is Not Null 为真,但是函数报错

Sub aa()
Dim A As Integer
A = 5 * 5
MsgBox A

If ThisDocument.Words.Item(5) <> Null Then
SaveAs ThisDocument.Words.Item(1) & ThisDocument.Words.Item(2) & ThisDocument.Words.Item(3) & ThisDocument.Words.Item(4) & ThisDocument.Words.Item(5) & ".doc"
ElseIf ThisDocument.Words.Item(4) <> Null Then
SaveAs ThisDocument.Words.Item(1) & ThisDocument.Words.Item(2) & ThisDocument.Words.Item(3) & ThisDocument.Words.Item(4) & ".doc"
ElseIf ThisDocument.Words.Item(3) <> Null Then
SaveAs ThisDocument.Words.Item(1) & ThisDocument.Words.Item(2) & ThisDocument.Words.Item(3) & ".doc"
ElseIf ThisDocument.Words.Item(2) Is Not Null Then
A = 5 * 5
MsgBox A
'SaveAs ThisDocument.Words.Item(1) & ThisDocument.Words.Item(2) & ".doc"
Else
SaveAs ThisDocument.Words.Item(1) & ".doc"
End If

End Sub

当我执行到A = 5 * 5有错误:
Run-time error '424':
Object required

是什么原因?


...全文
163 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧