利用Visual Basic实现自动化操作与屏幕保护程序开发
1. 使用ActiveX统计字符串中的单词数
在自动化操作中,使用Word进行字符串单词计数是一个实用的功能。以下是实现该功能的代码示例:
Private Sub cmdWords_Click()
Dim dlg As Word.Dialog
'Copy text into Word document
mdocSpell.Range = txtSpell.Text
'Create an object to hold dialog box settings
Set dlg = mdocSpell.Application.Dialogs _
(wdDialogDocumentStatistics)
'Count words and characters
dlg.Execute
'Display results in a Label control
Caption = Str(dlg.Words) & " words, " _
& Str(dlg.Characters) & " characters"
End Sub
操作步骤如下:
1. 从“Microsoft Word Spell Checking”部分创建的表单开始。
2. 添加一个名为 cmdWords 的命令按钮。
3. 运行时,在文本框中输入一些文本,然后点击命令按钮,即可显示单词和字符的数量。
超级会员免费看
订阅专栏 解锁全文
1228

被折叠的 条评论
为什么被折叠?



