- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 154
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-6-26
               
|
23#
發表於 2011-2-16 11:29
| 只看該作者
回復 22# txiec - Sub Ex()
- fd = ThisWorkbook.Path & "\" '文字檔目錄
- fs = Dir(fd & "*.txt") '目錄中的文字檔名
- Do Until fs = ""
- Open fd & "temp.txt" For Output As #2 '準備暫存檔
- Open fd & fs For Input As #1 '開啟要轉為大寫的文字檔作輸入用
- Do While Not EOF(1)
- Line Input #1, mystr
- If mystr Like "M/C(*),*" Then '如果該字串類似此樣式
- restr = Mid(mystr, InStr(mystr, "),")) '取得要轉為大寫的部份字串
- mystr = Replace(mystr, restr, UCase(restr)) '將原變數
- End If
- Print #2, mystr '將已經轉成大寫的字串寫入暫存檔
- Loop
- Close #1
- Close #2
- Open fd & fs For Output As #2 '打開需轉寫的文字檔準備寫入
- Open fd & "temp.txt" For Input As #1 '開啟已轉成大寫的暫存檔
- Do While Not EOF(1)
- Line Input #1, mystr '讀出暫存檔資料
- Print #2, mystr '將暫存檔字串寫入需修改檔案
- Loop
- Close #1
- Close #2
- Kill fd & "temp.txt" '刪除暫存檔
- Loop
- End Sub
複製代碼 |
|