我有一个VBA宏,它在运行X13 ARIMA席位之前以"datevalue“格式(即,年份选项卡、月份选项卡数据)写入txt文件。
它一直起作用,但最近只起作用了几次。当我查看它在季节性调整之前生成的.txt文件时,它在一行中间被中断了。在1998年到2018年7月之前,它像往常一样写文件,但比它停在小数点中间的位置还要多。
这是编写txt datevalue文件的代码的一部分。Ano和mes (年份和月份)是代码开始时的输入。
Private Sub copyData(ByVal mes As Integer, ByVal ano As Integer, rng As Range)
Dim sFileText As String
Dim iFileNo As Integer
Dim i, col As Double
i = rng.Row
col = rng.Column
ficar = True
iFileNo = FreeFile
Open "P:\Macro\X12\Input\serie1.txt" For Output As #iFileNo
'Writes the file with the time series
While Cells(i, col) <> ""
Print #iFileNo, ano & Chr(9) & mes & Chr(9) & Cells(i, col)
If (mes + 1) Mod 12 > 0 Then mes = (mes + 1) Mod 12 Else mes = 12
If mes = 1 Then ano = ano + 1
i = i + 1
Wend
Close #iFileNo
End Sub这是.txt文件的头
1998 1 4641.272855
1998 2 3943.235604
1998 3 5167.087047
1998 4 4629.068494
1998 5 4736.139222
1998 6 4703.891762
1998 7 5394.787069
1998 8 4155.992635
1998 9 5741.168184
1998 10 5460.08048这是尾巴,它在那里停止工作。
2018 4 13790.364479
2018 5 13259.844355
2018 6 14320.106493
2018 7 16101.08我猜现在的文件太长了。
更新!
我在Wend之前添加了一个MsgBox (如下所示),因此代码运行得更慢(在运行时我一直按enter键),并且它工作正常。所以我认为它破坏了文件的书写,因为太长时间了。
MsgBox ano & Chr(9) & mes & Chr(9) & Cells(i, col)发布于 2019-11-26 20:07:11
后续行动(如果有人遇到这个问题):
我认为这个文件对我的excel来说太长了,而且它是如何被淹没的。解决方案是在运行代码之前限制小数。所以我在我的excel文件上放了一个=圆形(xxx,2)!
希望能帮上忙!
https://stackoverflow.com/questions/54773359
复制相似问题