excel - ActiveSheet.QueryTables.Add(连接:在 VBA Excel Mac 中的问题)
问题描述
我尝试在现有的特殊格式 Excel 表中导入 csv 文件,我通过 MacScript 选择其文件名。然后,经过视图修改,文件名是:“/Users/用户名/Downloads/文件名.csv”
我将它存储在字符串变量 MyCSV
然后开始导入:
使用 ActiveSheet.QueryTables.Add(Connection:MyCSV, Range($A$2))
然后宏停止:运行时错误 1004(由应用程序或对象定义的错误)
我对其进行了测试,将变量 MyCSV bij 替换为完整的路径和文件名,它就像做梦一样!
现在,是否不允许使用变量,用 Connection: 标识文件?
非常感谢您的帮助
问候哈利
Sub ING_Import()
' ING_Import Macro
Dim browsePath, MyBrowseType, MyScript, MyFiles, MyFiles2, MyCSV, myPrompt As String
myPrompt = "Selecteer een CSV-bestand"
browsePath = "/Users/hanshuizinga/Downloads/"
MyBrowseType = Chr(34) & "csv" & Chr(34)
MyScript = "set CSVfile to (choose file of type {" & MyBrowseType & "} " & _
"with prompt """ & myPrompt & """ default location (""" & _
browsePath & """ as posix file as alias) multiple selections allowed " & "False" & ")" & vbNewLine & _
"set {TID, text item delimiters} to {text item delimiters, "",""}" & vbNewLine & _
"set CSVfile to CSVfile as text" & vbNewLine & _
"set text item delimiters to TID" & vbNewLine & _
"return CSVfile"
MyFiles = MacScript(MyScript)
MyFiles2 = Replace(MyFiles, "Macintosh SSD", "")
MyFiles2 = Replace(MyFiles2, ":", "/")
MyCSV = Chr(34) & "TEXT;" & MyFiles2 & Chr(34)
With ActiveSheet.QueryTables.Add(Connection:=MyCSV, Destination:=Range("$A$2"))
.Name = "Import laatste ING Transacties"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.RefreshPeriod = False
.TextFilePromptOnRefresh = False
.TextFilePlatform = 10000
.TextFileStartRow = 2
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
解决方案
推荐阅读
- spring-security - 无法使用提供的颁发者解析 OpenID 配置(带有 KeyCloak 的 JHipster)
- c - 使用字符串存储数字的长除法 1/N 算法,过长时创建符号/字母
- android - Firestore 和分页库 3.0
- c - 为什么我不能在我的代码中使用 `libmime`?(OSError:mime.so:未定义符号:magic_load)
- json - 成员类型更改时如何反序列化 JSON
- amazon-web-services - 使用 AWS 资源策略有条件地允许来自 Lambda 的默认 VPC 的流量
- python - 如何阻止空格键在 PyQt5 中触发聚焦的 QPushButton?
- r - 如何仅通过用于创建分组箱线图的两个因素之一标记 x 轴,其中散点图覆盖在 ggplot2 中?
- android - Android - 在数据绑定适配器中传递视图
- c# - 自动化事件网格时出现 ResourceDeploymentFailure 错误