将工作表转换为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
答案 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