问题描述
解决方案
'工程-引用-将Microsoft Excel 12.0 Object Library选中,'工程-部件-将Microsoft Common Dialog Control 6.0选中,'在窗体上添加一个按钮Command1对象,一个CommonDialog1通用对话框对象Private Sub Command1_Click()CommonDialog1.CancelError = TrueCommonDialog1.DialogTitle = ""指定要接收的Txt文件""CommonDialog1.Filter = ""文本文件(*.xls)|*.xls|所有文件(*.*)|*.*""CommonDialog1.InitDir = App.PathCommonDialog1.ShowOpenText1 = CommonDialog1.FileNameSet xlApp = CreateObject(""Excel.Application"")xlApp.Visible = TrueSet xlBook = xlApp.Workbooks.Open(Text1)If xlApp.Worksheets(""Sheet1"").Range(""A1"").Cells(2 2) = """" Then xlApp.Worksheets(""Sheet1"").Range(""A1"").Cells(2 3) = ""B2空""ElsexlApp.Worksheets(""Sheet1"").Range(""A1"").Cells(2 3) = ""B2不空""End IfMsgBox ""所要打开的Excel文件已经打开,下面将关闭""xlBook.SavexlApp.QuitSet xlApp = NothingEndEnd Sub搜一下就行了
时间: 2025-01-30 05:21:21