gpt4 book ai didi

excel - 如何用vba删除一个txt文件的内容?

转载 作者:行者123 更新时间:2023-12-04 01:07:02 25 4
gpt4 key购买 nike

我想与 SAP 进行交易,我使用 csv 文件作为导出文件,但最后我想删除该文件的内容而不删除文件本身。删除内容即可。

      Sub OpenCSVFile()
'
' Load the CSV extract
'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fpath & "\" & ffilename, Destination:=Range("$A$1"))
.Name = "text"
.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 = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With


With ActiveSheet
.Columns(1).EntireColumn.Delete 'delete first column
.Rows("1:7").EntireRow.Delete 'delete first 7 rows
End With

End Sub

最佳答案

Sub ClearContents()

Open "C:\Users\Username\Desktop\test1.csv" For Output As #1: Close #1
MsgBox "Clear complete"

End Sub

只需将文件路径更改为 csv 文件所在的位置即可。

关于excel - 如何用vba删除一个txt文件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56669947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com