以下VBA會列出所有檔案資訊
(不論是否該檔有沒有開啟,都可以得到正確檔案資訊)
Sub getDetailsOfFile()
Dim myShl As New Shell
Dim curFolder As Folder
Dim theItm As FolderItem
Dim Fn As Variant
Dim theTitle As String
Dim outStr As String
Dim i As Long
Fn = Application.GetOpenFilename
If Fn = "False" Then Exit Sub
Set curFolder = myShl.Namespace(CurDir)
Fn = Split(Fn, "\"): Fn = Fn(UBound(Fn))
With curFolder
theTitle = .GetDetailsOf(0, i)
Do While theTitle <> ""
outStr = outStr & theTitle & ": " & vbTab & .GetDetailsOf(.Items.Item(Fn), i) & vbCrLf
Debug.Print i & .GetDetailsOf(.Items.Item(Fn), i)
i = i + 1
theTitle = .GetDetailsOf(0, i)
Loop
End With
Set myShl = Nothing
MsgBox outStr
End Sub
請設定引用項目Microsoft Shell Controls and Automation
VBE=>工具=>設定引用項目=>勾選Microsoft Shell Controls and Automation
2008年7月24日 星期四
2007年10月29日 星期一
VBA 轉碼 UTF-8轉Big5
VBA 轉碼 UTF-8轉Big5
有些網頁的格式是以UTF-8編碼, 透過VBA以URLDownloadToFile下載該網頁後,若要進一步處理,會遇到中文變成亂碼的問題,用ADODB.Stream處理後可以轉成Big5碼.
Function UTF8ToBig5(HtmlFile)
Dim objStream As Object
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Type = 2
.Mode = 3
.Open
.Charset = "UTF-8" ' 或其他編碼
.LoadFromFile HtmlFile
UTF8ToBig5 = .ReadText
'也可透過 .SaveToFile 方法把檔案存檔
.Close
End With
End Function
有些網頁的格式是以UTF-8編碼, 透過VBA以URLDownloadToFile下載該網頁後,若要進一步處理,會遇到中文變成亂碼的問題,用ADODB.Stream處理後可以轉成Big5碼.
Function UTF8ToBig5(HtmlFile)
Dim objStream As Object
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Type = 2
.Mode = 3
.Open
.Charset = "UTF-8" ' 或其他編碼
.LoadFromFile HtmlFile
UTF8ToBig5 = .ReadText
'也可透過 .SaveToFile 方法把檔案存檔
.Close
End With
End Function
訂閱:
文章 (Atom)