(急)轉用了Office Excel 2007後這Macro不能執行?

2008-01-29 7:18 am
以下是Excel 一部分的巨集,我以前用Excel Office XP 是成功執行的,但近日轉用了Excel Office 2007便發生錯誤,不能成功執行,請問是否新版的句法要求改變了?要怎樣改才能成功執行?謝謝各位指教
'search default datafile
Application.FileSearch.LookIn = "C:\\數據統計\\恆生指數"
Application.FileSearch.Filename = "tableHSI.csv"
fs = Application.FileSearch.Execute
'print out database dir
If fs = 1 Then
UserForm1.TextBox1.Value = "C:\\數據統計\\恆生指數\\tableHSI.csv"
ElseIf fs = 0 Then
UserForm1.TextBox1.Value = "找不到資料庫!"
Else
End If

回答 (2)

2008-01-30 2:34 pm
✔ 最佳答案
Yes. Excel 2007 remove the Application.FileSearch function....so you cannot use the code anymore....

Here's some code I write...



**********************************************************
Sub OpenFile()


Filename = "C:\Test\tableHSI.csv"

Dim fso, msg
Set fso = CreateObject( "Scripting.FileSystemObject" )
If (fso.FileExists(Filename)) Then

Workbooks.Open Filename:= "C:\Test\tableHSI.csv"
MsgBox Filename & " exists."
Else
MsgBox "Cant find file "& Filename
End If

End Sub
**********************************************************

It actually find whether that file exists or not. If it does not exist, there's a pop up box says cant find file.


If the file is found, then the program will open the file.


You may want to modify the code for your own use.

I hope that helps.
參考: myself, internet ...
2008-01-31 4:55 am
Very Good ~


收錄日期: 2021-04-13 15:02:49
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080128000051KK03869

檢視 Wayback Machine 備份