我遇到一个问题,我想将文本文件中的值导入到我的excel文档中,但是当我一遍又一遍地运行宏以用新值刷新所述值时,它只是将其移动并添加了更多内容,因此需要删除值并替换它们,我自己没有编写此代码,因此我无法理解它的问题,因此在这里我恳求帮助
Sub ImportSaldo()
Call Shell("C:\import\GetFromFTP.bat", vbNormalFocus)
Dim fileName As String, folder As String
folder = "c:\import\"
fileName = "Saldot.txt"
ActiveCell.Offset(0, 0).Range("A1").Select
With ActiveSheet.QueryTables _
.Add(Connection:="TEXT;" & folder & fileName, Destination:=ActiveCell)
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
答案 0 :(得分:0)
.RefreshOnFileOpen = False,将其更改为True
打开文件后,应清除ActiveSheet中的现有值。