軟體: EXCEL VBA
版本: office 365
請問我要將https://goodinfo.tw/StockInfo/EquityDistributionClassHis.asp?STOCK_ID=3049中的3049改為sheet(Company)中的儲存格B2,
試了""https://goodinfo.tw/StockInfo/EquityDistributionClassHis.asp?STOCK_ID="" &
Sheets("Company").Range("B2").Value,VBA說語法錯誤,請問版上高手是否能幫忙解惑?
Application.CutCopyMode = False
ActiveWorkbook.Queries.Add Name:="Table 3", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " 來源 =
Web.Page(Web.Contents(""https://goodinfo.tw/StockInfo/EquityDistributionClassHis.asp?STOCK_ID=3049"")),"
& Chr(13) & "" & Chr(10) & " Data3 = 來源{3}[Data]," & Chr(13) & "" &
Chr(10) & " 已變更類型 = Table.TransformColumnTypes(Data3,{{""週別"", type
text}, {""統計 日期"", type date}, {""當月股價 收盤"", type number}, {""當月股
價 漲跌 (元)"", type number}, {""當月股價 漲跌 (%)"", type number}, {""各持股
等級股東之持股比例(%) 10張 以下"", type number" & _
"}, {""各持股等級股東之持股比例(%) 10至 50張"", type number}, {""各持
股等級股東之持股比例(%) 50至 100張"", type number}, {""各持股等級股東之持股比
例(%) 100至 200張"", type number}, {""各持股等級股東之持股比例(%) 200至 400張
"", type number}, {""各持股等級股東之持股比例(%) 400至 800張"", type number},
{""各持股等級股東之持股比例(%) 800至 1千張"", type number}, {""各持股等級股東
之持股比例(%) 超過 1千張"", type number}})" & Chr(13) & "" & Chr(10) & "in" &
Chr(13) & "" & Chr(10) & " 已變更類型" & _
""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data
Source=$Workbook$;Location=""Table 3"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 3]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_3"
.Refresh BackgroundQuery:=False
End With
End Sub