简体   繁体   English

删除csv文件,Excel vba中的最后一个字符

[英]Remove last character in csv file, Excel vba

I am generating a CSV file from Excel (2013) like this: 我正在从Excel(2013)生成CSV文件,如下所示:

.SaveAs Filename:= _
    filePath & MyFileName, _
    FileFormat:=xlCSV, _
    Local:=True, _

That works fine but at the last row I get semicolon in the end as well: 效果很好,但最后一行我最后也得到了分号:

994085;None ApS.;2;G; 12 ;31-12-2015; 40 ; -   ;Operational TB ;

How can I remove the last ; 我该如何删除最后一个; in that file? 在那个文件中?

I saw it is easy in a string. 我看到这很容易。 I am not sure I can put the whole file into string. 我不确定是否可以将整个文件放入字符串中。 It is around 6-700K characters. 它是大约6-700K个字符。 It has to go pretty fast no matter what I implement 无论我实施什么,它都必须非常快

Any ideas appreciated! 任何想法表示赞赏!

Open "partnumbers.txt" For Output As #2
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
If Right(xFname$, 1) = "1" Then
  Print #2, Left(xFname$, 13)
  ActiveCell.Offset(xRow) = Left(xFname$, 13)
End If
xRow = xRow + 1
xFname$ = Dir
Loop
End If
Close #2

Basically you could use something like this. 基本上,您可以使用类似这样的东西。 Here i am counting 13 characters and deleting the rest from each line in the txt; 在这里,我数了13个字符,并从txt的每一行中删除其余字符; obviously this code will need to be rearanged to your needs, but you can take a look at the theory of this. 显然,此代码将需要重新调整以满足您的需求,但是您可以看一下它的理论。 Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM