excel - how to set the decimal separator for printing to file different from the system setting -
using vba in excel 2010 want print contents of cell in worksheet decimal number file. using ´print #´ statement this. working in environment comma ´,´ system wide decimal separator. printout want point ´.´ decimal separator.
the following code not work:
public sub printdecimal() application.usesystemseparators = false application.decimalseparator = "." open "testfile.txt" output #1 print #1, activesheet.range("a1").value close #1 application.usesystemseparators = true end sub the documentation print # statement says:
all data written file using print # internationally aware; is, data formatted using appropriate decimal separator.
when change system wide settings in windows 7 enterprise control panel, desired output, not want.
since using macro, can take direct control of material being output text file:
public sub printdecimal() dim st string close #1 open "c:\testfolder\testfile.txt" output #1 st = range("a1").text st = replace(st, ",", ".") print #1, st close #1 end sub using .text property allows cell's value wysiwyg. rest string manipulation.
edit#1:
the reason posted code not work applying application.decimalseparator akin applying formats......the underlying value not change. run see difference:
sub demo() dim st string, st2 string application.usesystemseparators = false application.decimalseparator = "|" close #1 open "c:\testfolder\testfile2.txt" output #1 print #1, activesheet.range("a1").value & vbcrlf & activesheet.range("a1").text close #1 application.usesystemseparators = true end sub
Comments
Post a Comment