急急急!visual basic代码出错亟待高手纠正。

来源:百度知道 编辑:UC知道 时间:2024/09/19 19:02:21
本人系VB菜鸟,按书中提示抄录并试运行了下列visual basic代码,但是系统总是提示运行错误“对象变量或with块变量未设置”。请高手帮助指正并修改,分数不成问题。谢谢:

Sub user()
Dim i As Integer
Dim j As Integer
Dim h As Integer
Dim pageCount As Integer

Documents.Open "d:\dan.doc"
Selection.wholeStory
Selection.Copy
ActiveDocument.close
Documents(1).Select

pagecount=myrs.RecordCount*2-1 (★★程序提示此行代码有误★★
提示内容为“对象变量或with块变量未设置”。)
For i=1 to pageCount
Selection.InsertBreak Type:=wdSectionBreakNextPage
Next
'MsgboxActiveDocumentSectionsCount,vbInformation
For i=1 to myrs.RecordCount
ActiveDocument.Sections(i).Range.Select
Selection.paste
next
i=1
myrs.Movefirst
do until myrs.EOF

您是想实现复制和粘贴操作吧?多放一个rich textbox吧,先把您想要操作的文本读入Rtext(把richtextbox改名称)中
private sub command1_click()
dim a$
Rtext.text=""
open "d:\myfile.txt" for input as #1 'myfile为您要打开的文本名
do while not eof(1)
line input #1,a
Rtext.text=Rtext.text+a
loop
close #1
end sub
Private Sub command1_click() '剪切
Clipboard.Clear '清空剪贴板
Clipboard.SetText RText.SelText
RText.SelText = ""
End Sub

Private Sub command2_click() '复制
Clipboard.Clear
Clipboard.SetText RText.SelText
End Sub

Private Sub command3_click() '粘贴
RText.SelText = Clipboard.GetText
End Sub