[英]VBA : QueryTables : how to NOT take into account TextFileOtherDelimiter
I got a troubleshooting with VBA for Excel : When I use 我使用VBA for Excel进行了故障排除:使用时
With ActiveSheet.QueryTables.Add(Connection:=ConnString, Destination:=SomeRange)
.Name = _
" "
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileDecimalSeparator = ","
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
the import request automatically carries in this import the "other delimiter" that I requested on a manual import. 导入请求会自动在我的导入中携带我在手动导入中请求的“其他分隔符”。
ie I manually imported a file using "-" as delimiter and the macro is going to behave as if it included the line : 即我手动使用“-”作为分隔符导入了文件,宏将表现为好像包含以下行:
.TextFileOtherDelimiter = "-"
I tried to use 我尝试使用
.TextFileOtherDelimiter = False
but it doesn't work, because it behaves as 但它不起作用,因为它的行为与
.TextFileOtherDelimiter = "F"
My question : how can I specify that this import should only be parsed with "," delimiter and not ANY other one (regardless of any other import that can have occured on the machine before?) 我的问题:如何指定仅使用“,”定界符而不是任何其他解析符(无论以前在计算机上发生过任何其他导入),都应解析此导入?
For future reference, I did not find the way to force no other delimiter, but the two following workaround seem to work : 供将来参考,我没有找到不强制使用其他定界符的方法,但是以下两种解决方法似乎可行:
forcing the otherdelimiter to the same value as the first one (won't work if you have no first delimiter) 强制将otherdelimiter设置为与第一个定界符相同的值(如果没有第一个定界符,将不起作用)
.TextFileOtherDelimiter = ","
using a delimiter that never appears in the file (won't work if any char but the first delimiter could appear in the file) 使用永远不会出现在文件中的定界符(如果有任何字符,但第一个定界符可能会出现在文件中将不起作用)
.TextFileOtherDelimiter = "|"
As none of these two workarounds solves the problem in the general case, I don't mark it as suitable 由于这两种变通办法都不能解决一般情况下的问题,因此我认为它不适合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.