达人进来帮忙吖,我的操作word语句有一个地方运行不过去,搞不懂了

aspvbjava 2003-05-19 11:00:19
下面是 lxcc(虫莲) 达人给我的vb操作word代码,在word插入书签,然后写入文本,现在程序运行到
iCount = lvCase.ListItems.Count
的时候出现错误:要求对象。我不知道这句话什么意思,能给我解释一下吗?
谢谢谢!!!
急急急!!!


On Error Resume Next '忽略错误
Set appword = GetObject(, "Word.Application") '查找一个正在运行的Excel拷贝
If Err.Number <> 0 Then '如果 Excel 没有运行则
Set appword = CreateObject("Word.Application") '运行它
End If
Err.Clear '清除发生错误的 Err 对象
On Error GoTo 0 '保留普通错误进程

Dim dot As String
Dim doc As String

dot = App.Path & "\file report\上行公文.doc"
doc = App.Path & "\file report\temp.doc"
Dim i As Integer
Dim iCount As Integer

'下面一句就是运行出错误的地方

iCount = lvCase.ListItems.Count
For i = 1 To iCount
appword.Documents.Open FileName:=dot, _
ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
0
appword.Visible = True
appword.ActiveDocument.Close
appword.Documents.Add Template:=dot, NewTemplate:=False
With appword.Application
.Selection.GoTo Name:="BM_WFWH" '书签名称,以下类似
.Selection.TypeText Text:=lvCase.ListItems.Item(i).SubItems(2)

.Selection.GoTo Name:="BM_SQH"
.Selection.TypeText Text:=lvCase.ListItems.Item(i).SubItems(1)

.Selection.GoTo Name:="BM_SQDate"
.Selection.TypeText Text:=Format(lvCase.ListItems.Item(i).SubItems(3), "long date")

.Selection.GoTo Name:="BM_ZLMC"
.Selection.TypeText Text:=lvCase.ListItems.Item(i).SubItems(4)

.Selection.GoTo Name:="BM_SQR"
.Selection.TypeText Text:=lvCase.ListItems.Item(i).SubItems(5)


'.ActiveDocument.PrintPreview
End With
ActiveDocument.SaveAs FileName:=doc, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False

appword.ActiveDocument.PrintOut FileName:=doc, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
appword.ActiveDocument.Close
Next
...全文
42 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aspvbjava 2003-05-20
  • 打赏
  • 举报
回复
吧后面的参数都去掉,搞定了,谢谢吖
aspvbjava 2003-05-20
  • 打赏
  • 举报
回复
刚才运行到
appWord.ActiveDocument.PrintOut FileName:=doc, Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=2, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

错误提示:未找到命名参数
另外当我敲入appWord.的时候后边没有弹出属性菜单,请问怎么回事儿啊?
谢谢吖
aspvbjava 2003-05-20
  • 打赏
  • 举报
回复
哦,和和,谢谢,我去试试
lxcc 2003-05-20
  • 打赏
  • 举报
回复
for
next
删掉
对listview内的数据循环,如果你没有就删掉
lxcc 2003-05-20
  • 打赏
  • 举报
回复
lvcase是一个listview
lxcc 2003-05-20
  • 打赏
  • 举报
回复
删掉,笔误!

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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