实例1
Private Sub Command9_Click()
Dim xlApp1 As Excel.Application Dim xlBook1 As Excel.Workbook Dim xlSheet1 As Excel.Worksheet Set xlApp1 = CreateObject("Excel.Application") Set xlBook1 = xlApp1.Workbooks.Open("F:\vb\x1.xls") '打开已经存在的EXCEL工件簿文件 Set xlSheet1 = xlApp1.Worksheets.Item(2) xlApp1.Run "按钮1_Click" xlApp1.ActiveWorkbook.Saved = True '放弃存盘 xlApp1.Workbooks.Close ' xlApp1.Visible = True '显示excel Set xlApp1 = Nothing End Sub 实例2
Private Sub Command9_Click()
Dim xlApp1 As Excel.Application Dim xlBook1 As Excel.Workbook Dim xlSheet1 As Excel.Worksheet Set xlApp1 = CreateObject("Excel.Application") Set xlBook1 = xlApp1.Workbooks.Open("F:\vb\x1.xls") '打开已经存在的EXCEL工件簿文件 Set xlSheet1 = xlApp1.Worksheets.Item(2) '使用完毕 xlApp1.DisplayAlerts = False '避免弹出对话框 '使用完毕
xlBook1.Save Set xlSheet1 = Nothing xlBook1.Close (True) '关闭工作簿 Set xlBook1 = Nothing xlApp1.Quit '结束EXCEL对象 'xlApp.Close Set xlApp1 = Nothing '释放xlApp对象 propath ("EXCEL.EXE")'结束进程 End Sub
Public Function propath(proname As String) As String Dim objWMIService As Object Dim colProcesslist As Object Dim objProcess As Object Set objWMIService = CreateObject("winmgmts:{impersonationLevel=Impersonate}!root\cimv2") Set colProcesslist = objWMIService.ExecQuery("select * from win32_process where name=" & Chr(39) & proname & Chr(39)) For Each objProcess In colProcesslist propath = objProcess.ExecutablePath objProcess.Terminate '关闭程序 Next End Function |
|