|
楼主 |
发表于 2010-5-23 12:31
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
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 |
|