mình là người mới.voc vạch được 1 tí nên còn nhiều điều ko hiểu về excel mn thông cảm.mình cũng có tìm hiểu rồi nhưng mình qua ngu về khoản code nên ko biết kết hợp làm sao cho chuẩn.mn giúp mình chỉ cho mình 1 con đường sáng với ạ.
đây là code mình macro:
Sub Macro1()
'
' Macro1 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Queries.Add Name:="Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://www.hatomarksite.com/search/zentaku/agent/00070100003/""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 0]")
.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_0"
.Refresh BackgroundQuery:=False
End With
End Sub
do mình phai chạy rất nhiều trang web nên mình muốn tạo 1 vòng lạp cho hoạt động của mình.mỗi vòng lặp thì tự động những chỗ mag mình có gạch chân màu đỏ lên 1 đơn vị.
ví dụ dịa chỉ trang web là https://www.hatomarksite.com/search/zentaku/agent/00070100003/ thì sẽ thành https://www.hatomarksite.com/search/zentaku/agent/00070100004/
ActiveWorkbook.Queries.Add Name:="Table 0 ", Formula:= _ thành ActiveWorkbook.Queries.Add Name:="Table 0 (2)", Formula:= _
.CommandText = Array("SELECT * FROM [Table 0]") thành .CommandText = Array("SELECT * FROM [Table 0 (2)]")
.ListObject.DisplayName = "Table_0" thành .ListObject.DisplayName = "Table_0__2"
đây là code mình macro:
Sub Macro1()
'
' Macro1 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Queries.Add Name:="Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://www.hatomarksite.com/search/zentaku/agent/00070100003/""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 0]")
.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_0"
.Refresh BackgroundQuery:=False
End With
End Sub
do mình phai chạy rất nhiều trang web nên mình muốn tạo 1 vòng lạp cho hoạt động của mình.mỗi vòng lặp thì tự động những chỗ mag mình có gạch chân màu đỏ lên 1 đơn vị.
ví dụ dịa chỉ trang web là https://www.hatomarksite.com/search/zentaku/agent/00070100003/ thì sẽ thành https://www.hatomarksite.com/search/zentaku/agent/00070100004/
ActiveWorkbook.Queries.Add Name:="Table 0 ", Formula:= _ thành ActiveWorkbook.Queries.Add Name:="Table 0 (2)", Formula:= _
.CommandText = Array("SELECT * FROM [Table 0]") thành .CommandText = Array("SELECT * FROM [Table 0 (2)]")
.ListObject.DisplayName = "Table_0" thành .ListObject.DisplayName = "Table_0__2"