ACCESS VBA-导出文件在行的开头和末尾都有“ [重复项]

问题描述 投票:1回答:1

此问题已经在这里有了答案:

说明:我的代码导入一个文本文件,并在特定的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"
vba ms-access access-vba
1个回答
1
投票

[Write #将处理数据,以便将其与Write #一起读入结构化变量。

这包括用双引号引起来的字符串。

如果您不想进行任何处理/格式化,请使用Input #而不是Print #

Print #
© www.soinside.com 2019 - 2024. All rights reserved.