APP.path在使用过程中,总不是很顺畅。经常报错,
如下代码,出现1004错误,无法打开对应的文件。
1、我确定文件位置和程序在一个文件下;
2、我过程检查插入print fullpath,所显示的地址是正确的;
3、我将显示的地址直接提换如下语句中的fullpath
Set xlBook = xlApp.Workbooks.Open("fullpath")
程序也能运行成功。
求大神指点一下迷津
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim fullpath As String
If Right(App.Path, 1) = "\" Then
fullpath = App.Path + "temp.xlsx"
Else
fullpath = App.Path + "\" + "temp.xlsx"
End If
Print fullpath
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("fullpath")
xlApp.Visible = True
Set xlsheet = xlBook.Sheets("sheet1")
Text1.Text = xlsheet.Range("A1").Value
xlBook.Close
xlApp.Quit
End Sub