|
 |
推荐文章 |
|
|
|
|
|
|
|
|
|
|
| 作者:本站收集 日期:2005-8-4 11:33:15 |
|
|
Visual Basic 5.0具有简单、易学等特点,深受初学者的欢迎,但也有一些不如人意的地方。例如,不能像Word 97那样进行拼写检查,不能像Excel 97那样具有很多的函数。如果我们能将Word 97和Exce l97的功能使用在Visual Basic 5.0中,就可以使VB达到锦上添花的目的。
我们知道所有Office 97 应用程序都提供了ActiveX对象,我们可以在Visual Basic 5.0中使用它们。
调用Word 97
要想在VB中调用Word 97,首先要打开VB的“工程”菜单中的“引用”项目,并在该项目对话框中选定“Microsoft Word 8.0 Object Library”就可以了。
下面我们举例说明调用Word 97中的“拼写检查”和“单词统计”功能。首先新建一个工程并在窗体上放置一个TextBox控件和两个CommandButton控件,然后添入如下的代码:
Option Explicit
Dim Doc As New Document
Dim Visi As Boolean
图1 调用Word 97
′拼写检查
Private Sub Command1-Click()
Form1.Caption = “拼写检查"
Doc.Range.Text = Text1
′确定范围
Doc.Application.Visible = True ′将Word 97变为可见
AppActivate Doc.Application.Caption
′激活Word 97
Doc.Range.CheckSpelling
′拼写检查
Text1 = Doc.Range.Text
Text1 = Left(Text1, Len(Text1) - 1)
AppActivate Caption
End Sub
′统计单词数
Private Sub Command2-Click()
Dim Dlg As Word.Dialog
Doc.Range = Text1.Text
Set Dlg = Doc.Application.Dialogs
(wdDialogDocumentStatistics)
Dlg.Execute ′统计单词和字符
Form1.Caption =“单词数:" & Str(Dlg.Words) & “词"
& Str(Dlg.Characters) & “字符" ′显示统计结果
End Sub
Private Sub Form-Load()
Form1.Caption =“调用Word 97"
Text1.Text = “"
Command1.Caption = “拼写检查"
Command2.Caption = “统计单词"
′使应用程序可见
Visi = Doc.Application.Visible
End Sub
′关闭应用程序
Private Sub Form-Unload(Cancel As Integer)
If Visi Then ′关闭文件
Doc.Close savechanges:=False
Else
Doc.Application.Quit savechanges:=False ′关闭 Word 97
End If
End Sub |
|
|
|
|
|
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
|
|
|
|
|
责任编辑: 原点 |
投稿作者: 本站收集 |
|
|
信息来源: 网络 |
录入时间: 2005-8-4 11:33:15 |
|
|
|
| |
|