下面的VBA代碼,用於保存Excel數據導入.dat文件,完全適用於英文單詞,但不適合非英語。保存Excel數據導入.dat文件,包括非英文單詞
你應該怎麼我修改它來處理非英語單詞?
Sub Save_Click()
Dim FileName As String
Dim wks As Worksheet
Set wks = ThisWorkbook.Sheets(1)
Dim rowRange As Range
Dim colRange As Range
Dim LastCol As Long
Dim LastRow As Long
Dim ColCounter As Integer
Dim rowCounter As Integer
Dim metarow As Integer
Dim mergerow As Integer
Dim noofmetacolumns As Integer
Dim j As Integer
FileName = Application.GetSaveAsFilename
Open FileName For Output As #1
LastRow = wks.Cells(wks.Rows.Count, "A").End(xlUp).Row
Set rowRange = wks.Range("A1:A" & LastRow)
'Loop through each row
rowCounter = 0
metarow = 0
mergerow = 0
noofmetacolumns = 0
For Each rrow In rowRange
'Find Last column in current row
metarow = 0
mergerow = 0
rowCounter = rowCounter + 1
LastCol = wks.Cells(rowCounter, wks.Columns.Count).End(xlToLeft).Column
Set colRange = wks.Range(wks.Cells(rowCounter, 1), wks.Cells(rowCounter, LastCol))
'Loop through all cells in row up to last col
ColCounter = 0
For Each cell In colRange
'Do something to each cell
'Debug.Print (cell.Value)
If ColCounter <> 0 Then
Print #1, "|";
Print #1, cell.Value;
Else
Print #1, cell.Value;
End If
ColCounter = ColCounter + 1
If ColCounter = 1 Then
If cell.Value = "METADATA" Then
metarow = 1
End If
If cell.Value = "MERGE" Then
mergerow = 1
End If
End If
Next cell
If metarow = 1 Then
noofmetacolumns = ColCounter
End If
If mergerow = 1 Then
For j = ColCounter + 1 To noofmetacolumns
Print #1, "|";
Next j
End If
Print #1, vbNewLine;
Next rrow
Close #1
MsgBox ("File Saved Successfully")
End Sub
Sub ImportFile()
Dim Filt As String
Dim Title As String
Dim FileName As String
Filt = "HDL Dat Files (*.dat),*.dat"
Title = "Select a HDL Dat File to Import"
FileName = Application.GetOpenFilename(FileFilter:=Filt, Title:=Title)
'Procedure call. | is defined as separator,
'and data is to be inserted on "Sheet1".
copyDataFromHDLDatFileToSheet FileName, "|", "Sheet1"
Sheets(1).Select
End Sub
'適合英文單詞但不適合非英文' - 你的意思是?你應該更具體,並提供有關你的問題的更多細節。 –
您正在寫入一個文本文件。您可能希望看到[這](https://stackoverflow.com/questions/18905489/how-to-save-a-unicode-character-to-a-text-file) –
非英文的意思是像阿拉伯語和中國。 .write此代碼用於將excel表單數據轉換爲.dat文件格式。 –