这是我之前帮助过的问题的延续。我试图组合2个子例程,以便创建的文本文件在结尾处删除了空格。看下面的代码,我得到一个路径文件错误 - 打开inFile输入为#1
调试后,我可以看到存储在strFile中的文件名在调用第二个例程时消失了。任何人都可以看到我的错误是为什么它这样做,并帮我解决它吗? AltText_V2是第二个例程。我已经更新了代码,只包括问题所在的部分
Option Explicit
Public Sub AltText_V2()
Dim inFile As String
Dim outFile As String
Dim data As String
Dim strFile As String
'Ensures that the file open directory is always the same
ChDir "S:\MERIT OUTPUTS FOLDER\MSI Recruitment Limited\"
'inFile = Application.GetOpenFilename
inFile = strFile
Open inFile For Input As #1
outFile = inFile & ".txt"
Open outFile For Output As #2
Do Until EOF(1)
Line Input #1, data
If Trim(data) <> "" Then
Print #2, data
End If
Loop
Close #1
Close #2
Kill inFile
Name outFile As inFile
MsgBox "File alteration completed!"
End Sub
答案 0 :(得分:0)
我实际上已经解决了。我只是简单地在子例程之外声明了变量,并且它处理得很好看,所以它看起来像这样。
weather