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
在引用项目找不到Excel、Word等Office软体Lib的解决法
●底下有些文章是如何把资料丢到Office软体来帮我们列印,为了加快程式的开发速度,小瓜瓜会选择载入Lib的方式来把应用程式当成VB的一部份,只要在物件后打个点,所有方法属性就列出来,不用死背也不用看VBA的说明档,但有些网友是使用其它版本的Office,可能会找不到Lib可以来引用,该如何解决?
●底下是没有引用Lib来控制Office软体的方法:
○Word
(一般)
Dim MyDocApp As Object
Private Sub Command1_Click()
Set MyDocApp = CreateObject("Word.Application")
MyDocApp.Visible = True
End Sub
○Excel
(一般)
Dim MyXlsApp As Object
Private Sub Command1_Click()
Set MyXlsApp = CreateObject("Excel.Application")
MyXlsApp.Visible = True
End Sub
○PowerPoint
(一般)
Dim MyPptApp As Object
Private Sub Command1_Click()
Set MyPptApp = CreateObject("PowerPoint.Application")
MyPptApp.Visible = True
End Sub