exe文件跟文件夹的根目录一样,要引用文件夹下面的Excel部分单元格的数据各位高手帮我解答下,新人的第一条提问
'工程-引用-将Microsoft Excel 12.0 Object Library选中,
'工程-部件-将Microsoft Common Dialog Control 6.0选中,
'在窗体上添加一个按钮Command1对象,一个CommonDialog1通用对话框对象
Private Sub Command1_Click()
CommonDialog1.CancelError = True
CommonDialog1.DialogTitle = "指定要接收的Txt文件"
CommonDialog1.Filter = "文本文件(*.xls)|*.xls|所有文件(*.*)|*.*"
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
Text1 = CommonDialog1.FileName
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open(Text1)
If xlApp.Worksheets("Sheet1").Range("A1").Cells(2, 2) = "" Then
xlApp.Worksheets("Sheet1").Range("A1").Cells(2, 3) = "B2空"
Else
xlApp.Worksheets("Sheet1").Range("A1").Cells(2, 3) = "B2不空"
End If
MsgBox "所要打开的Excel文件已经打开,下面将关闭"
xlBook.Save
xlApp.Quit
Set xlApp = Nothing
End
End Sub
搜一下就行了