如何通过unicode编码以dbf格式存储excel工作表的表格范围?

我正在使用Excel 2010,并需要通过unicode编码在dbf中存储一系列表。 我试着吼道:

Workbook.SaveAs FileName:="test.dbf", FileFormat:=xlDBF4, CreateBackup:=False 

但得到错误。

我怎样才能做到这一点?

您可能需要考虑使用Scripting.FileSystemObject(fso),因为使用unicode时,文件编码方式和fso使您可以更好地控制文件。 例如,在我的一个项目中,我需要将文件保存为普通的utf-8而不是utf-8-bom。 默认行为是将文件保存为utf-8-bom,这意味着有3个隐藏字符,称为位于文件开头的字节顺序标记(BOM)。 在下面的代码中,这三个字符通过复制到一个新的stream被删除,然后保存为普通的utf-8文件

 Dim fso As Scripting.FileSystemObject, stream1 As Stream, stream2 As Stream Sub saveFileAfterRemovingBOM(path As String) stream1.Position = 3 'skip BOM (byte order mark) Set stream2 = CreateObject("ADODB.Stream") With stream2 .Type = adTypeBinary .Mode = adModeReadWrite .Open stream1.CopyTo stream2 stream1.Flush stream1.Close .SaveToFile path, adSaveCreateNotExist 'creates the file if it doesn't exist .Flush .Close End With End Sub 

Stream&Scripting.FileSystemObject需要在VBE中添加引用,如下所示:Microsoft脚本运行时和Microsoft ActiveX数据对象库(V16.1自10/16)。 在VBE中添加这些使用工具 – >参考…

在这里输入图像说明