现在有一word文件,里面加了一个TextBox控件,还有一个Button按钮,在VB6里写代码怎么取到这个word里的textBox里的text值,还有怎么调用Button1_Click()这个事件?
解决方案 »
- 注册了系统热键,用什么方法激活热键最好?(用Timer和死循环就不要了)
- 如何判断outlook的task下文件夹是否存在?
- 强烈欢迎高手高手高高手一指点一下动态打印问题
- 简单的问题
- 关于monthview的问题
- 由于大家帮助。我把实验代码公开。其中有各位的一部分。(侵权误怪,它也源于大家)还有各位有好的代码,贴出点为了新手。
- 一个未知格式.NFS应该用什么软件打开呢?
- 那有InstallShield下载(中英文都可以,版本要6.0以上),非常感谢.
- !!!!!!如何在VB中重建系统图标缓存!!!!!!!!
- 在TEXT中接受键盘输入时,如果不是需要显示的字符就不显示出来如何实现?
- 如何禁止字段内容重复.请教.
- 请问,那本参考书上有对这个API数据结构中定义的各个变量的详细解释
如:
dim wdDoc as document
.......
msgbox wdDoc.TextBox1.Text要调用
Private Sub CommandButton1_Click()End Sub
应把Private去掉,这些都与Form一样。
我的VB工程中的代码如下:
Private Sub Command1_Click()
Dim doc
Set doc = CreateObject("word.application")
doc.Visible = True
doc.Documents.Open "c:\22.doc"
'msgbox doc.ThisDocument.TextBox1.Text '这行报错,我该怎么写,请高手指点End Sub
只是这种方法需要打开一个word文档
这个问题应该使用word对象解决是最好的
以qq为例
Option Explicit
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const BM_CLICK = &HF5
Private Const WM_SETTEXT = &HC
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HEPrivate Sub Command3_Click()
Dim t As Long
Dim b As Long
Dim d As Long
Dim clong As Long
t = FindWindow("#32770", vbNullString)
b = FindWindowEx(t, ByVal 0&, "Edit", vbNullString) '找到文本框的句柄
Dim astr As String * 256
SendMessage b, WM_SETTEXT, 0, ByVal Text1.Text
d = FindWindowEx(t, ByVal 0&, "Button", "登录")
clong = SendMessage(b, WM_GETTEXTLENGTH, 0, vbNull)
clong = Len(astr)
SendMessage b, WM_GETTEXT, clong, ByVal astr
Debug.Print astr
SendMessage d, BM_CLICK, 0, 0 '发送消息点击按钮End Sub
dim wdApp
Dim doc
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
set doc =wdApp.Documents.Open "c:\22.doc"
msgbox doc.TextBox1.Text End Sub