将Excel文件转换为PRN提供不同的语言数据

时间:2019-04-17 17:13:43

标签: excel vba

将工作表转换为prn后,将其上传到erp时会出错,当我将prn转换为txt格式时,我看到了某种中文书写的解决方法。下面的代码在“ A”行中添加值+1并转换为prn

Sub CONVERT()

Dim vcounter As Long
Dim ws As Worksheet

For Each ws In Sheets
  ws.Activate
  vcounter = 2
  While Range("A" & vcounter).Value <> ""
    Range("a" & vcounter).Value = Range("a" & vcounter).Value + 1   
    vcounter = vcounter + 1
  Wend
  Application.DisplayAlerts = False
  ActiveSheet.SaveAs Filename:="D:\birla soft\" & ActiveSheet.Name & ".prn"
Next ws

End Sub

1 个答案:

答案 0 :(得分:2)

您正在保存扩展名为.prn的.xlsm / .xlsx文件;并不能使它成为.prn文件,它仍然是.xlsm / .xlsx文件-扩展名不是决定文件格式的因素,它只是一个方便的指示器,可供我们细微的人识别何时看到的内容我们浏览文件。您想为XlFileFormat提供一个xlTextPrinter SaveAs method参数:

ActiveSheet.SaveAs Filename:="D:\birla soft\" & ActiveSheet.Name & ".prn", xlTextPrinter

关于此的注释:

ws.Activate

您不需要它。而是使用Range对象限定这些ws调用-并且您要迭代Worksheets集合(Sheets可能包含各种非工作表类型):< / p>

For Each ws In ActiveWorkbook.Worksheets ' or did you mean to iterate sheets in ThisWorkbook?
    Do While ws.Range(...)
        ws.Range(...) = ws.Range(...) + 1
        vcounter = vcounter + 1
    Loop
    Application.DisplayAlerts = False
    ws.SaveAs FileName:="..." & ws.Name & ".prn", FileFormat:=xlTextPrinter
Next