Home » excel » vba – convert excel file into prn gives different language data

vba – convert excel file into prn gives different language data

Posted by: admin May 14, 2020 Leave a comment

Questions:

after converting my sheet into prn it gives error during upload on my erp ,when i convert prn into txt format i saw some kind of chinese written how to fix this problem. below code add value +1 in row “A” and convert into 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
How to&Answers:

You’re saving a .xlsm/.xlsx file with a .prn extension; that doesn’t make it a .prn file, it’s still a .xlsm/.xlsx file – the extension isn’t what determines the file’s format, it’s just a convenient indicator for us puny humans to recognize what we’re looking at when we browse through files. You want to supply a xlTextPrinter XlFileFormat argument to the SaveAs method:

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

A note about this:

ws.Activate

You don’t need it. Instead, qualify these Range calls with the ws object – and you want to iterate the Worksheets collection (Sheets may contain all kinds of non-worksheet sheet types):

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