[VBA ] Excel開啟新檔案

看板Visual_Basic作者 (fala)時間19年前 (2006/10/14 23:14), 編輯推噓3(308)
留言11則, 2人參與, 最新討論串1/1
請問一下以下的程式碼是否哪裡出了問題,我在其他台電腦都可以用, 可是一回到家用自己的電腦發現程式就不能跑了,原因在於找不到檔案。 從區域變數視窗中可以看到,我的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

10/16 11:09, , 1F
從"區域變數視窗"只能看出路徑字串吧? 請問您是如何看出
10/16 11:09, 1F

10/16 11:11, , 2F
"找到檔案並開啟"的呢?
10/16 11:11, 2F

10/17 00:42, , 3F
因為我會讀dfile2 & dfile2 檔案內的數值,確定有讀到數值。
10/17 00:42, 3F

10/17 00:42, , 4F
我記得書上寫用Open開檔案如果檔案不存在,會自行產生一個新檔
10/17 00:42, 4F

10/17 00:43, , 5F
請問一下是因為excel版本的關係嗎?
10/17 00:43, 5F

10/17 00:44, , 6F
原始檔我是用excel2000寫的, 我自己的電腦是excelXP
10/17 00:44, 6F

10/17 09:30, , 7F
我個人使用經驗, Open不會幫你新增檔案耶, 2000 XP都用過...
10/17 09:30, 7F

10/17 09:35, , 8F
Sorry..剛看了說明, 會產生新檔, 嗯, 我沒用過這個方式新增過
10/17 09:35, 8F

10/17 09:37, , 9F
我大多是使用NewFile ^^|
10/17 09:37, 9F

10/17 23:53, , 10F
我後來的解決方法是直接自己製造一個新檔案(確定有讀到檔案)
10/17 23:53, 10F

10/17 23:54, , 11F
不過卻沒有辦法把檔案寫入我的寫法是Write #3, deltad,
10/17 23:54, 11F
文章代碼(AID): #15CFxg8n (Visual_Basic)
文章代碼(AID): #15CFxg8n (Visual_Basic)