|
楼主 |
发表于 2010-5-23 12:31
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
vb打开excel
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
Private Sub Form_Load()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim WordHwnd As Long, Pid As Long, strClassName As String * 255
'WordHwnd = FindWindow(vbNullString, "Microsoft Excel - Book1") '当判断一个具体的文件时,把此文件的标题名写上
WordHwnd = FindWindow("XLMAIN", vbNullString) '此句是只要有一个excel文件打开,就视为已经打开
If WordHwnd <> 0 Then
MsgBox "发现excel正在运行,请先关闭excel后再运行本程序", , "浙江省毕业证书打印程序"
End
Else
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
'Set xlBook = xlApp.Workbooks.Open(App.Path & "\main.dll") '打开已经存在的EXCEL工件簿文件
' Workbooks.Open FileName:=ThisWorkbook.Path & "\test.xls", Password:=111, writeResPassword:=222
xlApp.Workbooks.Open FileName:=App.Path & "\main.dll"
xlApp.Caption = "浙江省初中毕业证书打印程序"
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
End
' MsgBox "excel 没有运行"
End If
End Sub |
|