excel - .Refresh BackgroundQuery:=False ERROR excel vba
问题描述
我在“.Refresh BackgroundQuery:=False”行收到错误
这个宏过去在我的机器上工作正常,当我转移到虚拟机时它没有工作,我得到的错误是这样的:
我的代码:
请注意,所有路径都已更改为新路径,所以没问题
Sub Csv()
Debug.Print ThisWorkbook.Path
Application.DisplayAlerts = False
Workbooks.Add
ActiveWorkbook.Queries.Add Name:="account_Transactions_Other", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(File.Contents(""C:\Users\Alfalakbot4\Desktop\New folder\account_Transactions_Other.txt""),[Delimiter=""#(tab)"", Columns=7, Encoding=1252, QuoteStyle=QuoteStyle.Csv])," & Chr(13) & "" & Chr(10) & " #""Change Type"" = Table.TransformColumnTypes(Source,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}, " & _
"{""Column5"", type text}, {""Column6"", type text}, {""Column7"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Change Type"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=account_Transactions_Other;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [account_Transactions_Other]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "account_Transactions_Other"
.Refresh BackgroundQuery:=False
End With
ActiveSheet.ListObjects("account_Transactions_Other").Unlist
Rows("1:4").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Style = "Normal"
Columns("A:A").Select
Selection.NumberFormat = "@"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
Range("A1").Select
Workbooks(2).Activate
End Sub
解决方案
ListObject.Refresh
不采用任何参数,并且仅适用于链接到 SharePoint 的列表。
https://docs.microsoft.com/en-us/office/vba/api/excel.listobject.refresh
推荐阅读
- python - 硒元素选择:Instagram 评论
- reactjs - Sweetalert2 React Content 根本不起作用
- list - 返回两个值的 Erlang 函数
- r - dbplyr 函数相当于 sql 中的 EXISTS
- python - python脚本适用于windows但不适用于linux
- python - 如何在python中使用requests和beautifulsoup对网站的所有页面进行分页
- javascript - HTML Canvas 重叠多边形热图
- r - lapply 问题:如何在不产生错误的情况下进一步简化
- python - Sympy subs 不输出替换表达式?
- debian - 当 TigerVNC 查看器处于全屏状态并且系统从睡眠中唤醒时,键盘停止工作