作者mdy (fala)
看板Visual_Basic
標題[VBA ] Excel開啟新檔案
時間Sat Oct 14 23:23:53 2006
請問一下以下的程式碼是否哪裡出了問題,我在其他台電腦都可以用,
可是一回到家用自己的電腦發現程式就不能跑了,原因在於找不到檔案。
從區域變數視窗中可以看到,我的dfile1跟dfile2都有找到檔案並且開
啟,但是當我想利用dfile2的名字製造一個新檔案時,卻跟我說找不到檔案,
但是我在其他台電腦都可以用,只有自己家裡的電腦不能跑,請問一下是啥
緣故,謝謝。
我的部分程式碼如下:
dfile1 = Dir(DataPath1, vbNormal) 'get filename of the 1st file
dfile2 = Dir() 'get filename of the 2nd file
Open DataPath1 & dfile1 For Input As #1 'open file
Open DataPath1 & dfile2 For Input As #2 'open file
If dfile1 <> "" And dfile2 <> "" Then
Open DataPath1 & "dvt" & dfile2 For Output As #3
End If
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.216.187.73
1F:推 qsss:從"區域變數視窗"只能看出路徑字串吧? 請問您是如何看出 10/16 11:09
2F:→ qsss:"找到檔案並開啟"的呢? 10/16 11:11
3F:→ mdy:因為我會讀dfile2 & dfile2 檔案內的數值,確定有讀到數值。 10/17 00:42
4F:→ mdy:我記得書上寫用Open開檔案如果檔案不存在,會自行產生一個新檔 10/17 00:42
5F:→ mdy:請問一下是因為excel版本的關係嗎? 10/17 00:43
6F:→ mdy:原始檔我是用excel2000寫的, 我自己的電腦是excelXP 10/17 00:44
7F:推 qsss:我個人使用經驗, Open不會幫你新增檔案耶, 2000 XP都用過... 10/17 09:30
8F:推 qsss:Sorry..剛看了說明, 會產生新檔, 嗯, 我沒用過這個方式新增過 10/17 09:35
9F:→ qsss:我大多是使用NewFile ^^| 10/17 09:37
10F:→ mdy:我後來的解決方法是直接自己製造一個新檔案(確定有讀到檔案) 10/17 23:53
11F:→ mdy:不過卻沒有辦法把檔案寫入我的寫法是Write #3, deltad, 10/17 23:54