此问题已经在这里有了答案:
说明:我的代码导入一个文本文件,并在特定的col空格处将其更改为数字19。我成功地通过在vba中使用left和right来做到这一点。
我不知道为什么,但是我的书面代码在导出的循环的末尾添加了“。我已经在寻找解决方案,并且发现了这个问题Remove specific characters at beginning and end of string
我的代码有问题吗?我现在很困惑。
我的代码:
Sub Text()
'open File and save as string
Dim strFilter As String
Dim strFileName As String
Dim strFileNameSecond As String
strFileNameSecond = "new.txt"
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.TXT)", "*.TXT")
strFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
'load selected file and save as new file
Dim strZeile
Dim strRepMid As String
Open strFileName For Input As #1
Open strFileNameSecond For Output As #2
Do While Not EOF(1)
Line Input #1, strZeile
strRepMid = Left(strZeile, 40) & "19" & Right(strZeile, 68)
Write #2, strRepMid
Loop
Close #1 'close file
Close #2
End Sub
我的文本文件:
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
kjhcae48ovawpovmslövsae 0000000000 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr
导出后的文件:
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"
"kjhcae48ovawpovmslövsae 000000000019 jhkfkgnskhvfnslkfvmkjrdacösle<nvsel,fösfvjmykljc,gkvyndngmbrhjgsr"