Dim objword as word.application Dim objDoc as word.Documentprivate sub cmdStart_click() 'Start Word and make it visible set objWord=New word.Application objWord.visuble=True
'Create a new document set objDoc=objWord.Documents.Add '打开一个已有的文档 'Set objDoc=objWord.Documents.Open("C:\Temp\Luqingming.Doc")
'Make it activate document objDoc.Activate End Sub private Sub cmdClose_click()
'Close word without saving changes objWord.Quit False '如果你使用 objDoc.Close False 则只关闭文档 'Destroy object reference set objWord=NothingEnd Sub 本程序只有一个框架,没有出错处理,还需你自己完善。
关闭打开指定路径的windows窗口在一个模块文件中写入以下代号: Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (Byval IpClassName As String,Byval IpWindowName as STring) as Long '你还需在此加入一个SendMessage API'IpClassName 是窗口的类型; IpWindowName 是窗口的标题Sub TestCloseWindow(Byval sWindowCaption as String) dim hwndCurrent as Long '定义一个窗口句柄 dim lClose as Long hwndCurrent=FindWindow(vbNullString,sWindowCaption)
if hwndCurrnt=0 msgbox “你指定的” & sWindowCaption "窗口没有打开" exit sub else lClose=SentMessage(hwndCurrent,WM_CLOSE,0&,0&) endifend sub
有时间,给个例子好吗?谢谢!!
Dim objword as word.application
Dim objDoc as word.Documentprivate sub cmdStart_click()
'Start Word and make it visible
set objWord=New word.Application
objWord.visuble=True
'Create a new document
set objDoc=objWord.Documents.Add
'打开一个已有的文档
'Set objDoc=objWord.Documents.Open("C:\Temp\Luqingming.Doc")
'Make it activate document
objDoc.Activate End Sub
private Sub cmdClose_click()
'Close word without saving changes
objWord.Quit False '如果你使用 objDoc.Close False 则只关闭文档
'Destroy object reference
set objWord=NothingEnd Sub
本程序只有一个框架,没有出错处理,还需你自己完善。
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(Byval IpClassName As String,Byval IpWindowName as STring) as Long
'你还需在此加入一个SendMessage API'IpClassName 是窗口的类型; IpWindowName 是窗口的标题Sub TestCloseWindow(Byval sWindowCaption as String) dim hwndCurrent as Long '定义一个窗口句柄
dim lClose as Long
hwndCurrent=FindWindow(vbNullString,sWindowCaption)
if hwndCurrnt=0
msgbox “你指定的” & sWindowCaption "窗口没有打开"
exit sub
else
lClose=SentMessage(hwndCurrent,WM_CLOSE,0&,0&)
endifend sub