vb打开excel文件的相关操作

前端之家收集整理的这篇文章主要介绍了vb打开excel文件的相关操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Dim xlApp As EXCEL.Application
Dim xlBook As EXCEL.Workbook
Dim filename
Dim reportini As String

filename = "\ReportModel\BatchReport.xlsm" reportini = App.Path + "\report.ini" On Error Resume Next gstrLanguage = getstring(reportini,"database","Language") Call TextIni Set xlApp = GetObject(,"Excel.Application") '判断EXCEL是否打开 If Err.Number <> 0 Then Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象 xlApp.Visible = False '设置EXCEL对象不可见 End If Err.Clear If Dir(App.Path & filename) = "" Then '判断文件是否存在 MsgBox Msg_7,vbOKOnly,Title_SysMsg Exit Sub End If '判断文件是否打开 For Each xlBook In xlApp.Workbooks If xlBook.Name = Right(filename,16) Then MsgBox Msg_6,Title_SysMsg xlBook.Activate xlApp.WindowState = xlMaximized Exit Sub End If Next Set xlBook = xlApp.Workbooks.Open(App.Path & filename) '打开工件簿文件 xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL启动宏 'xlBook.RunAutoMacros (xlAutoClose) '运行EXCEL关闭宏 xlApp.Visible = True

原文链接:https://www.f2er.com/vb/259169.html

猜你在找的VB相关文章