麻辣家族討論版版's Archiver

CCL99 發表於 2021-8-28 23:58

要如何把VBA所產生的 檔案 存成 UTF-8編碼?

[i=s] 本帖最後由 CCL99 於 2021-8-29 00:00 編輯 [/i]

我用Excel 來寫HTML程式,朋友幫我寫巨集把Excel轉成純文字檔的 HTML,可是這純文字檔的編碼是ANSI 無法讓我正常使用多位元字如 utf-8 或 utf-16。
在以下的巨集程式碼,要增加什麼碼才能把產生的檔案存成utf-8編碼?[code]Public Sub WriteFile()

   Const FileNum = 1
   Dim FilePath As String
   Dim R As Long
   Dim C As Long
   Dim Outline As String
   Dim LastRow As Long
   
   FilePath = Replace(ThisWorkbook.FullName, ".xlsm", ".html")
   
   Open FilePath For Output As #FileNum
   
   R = 1
   LastRow = Cells(Rows.Count, "B").End(xlUp).Row
   
   For R = 1 To LastRow
      Outline = ""
      For C = 1 To 21 ' B to U
         Outline = Outline & Cells(R, C)
      Next C
      Print #FileNum, Trim(Outline)
   Next R
   
   Close #FileNum
   
   MsgBox "File complete."

End Sub[/code]

linyancheng 發表於 2022-2-8 09:33

使用FileSystemObject

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供