达人进来帮忙吖,我的操作word语句有一个地方运行不过去,搞不懂了
下面是 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