Thứ Tư, 18 tháng 5, 2022

Hướng dẫn lập trình VBA

https://www.youtube.com/watch?v=OSfcpLGVLOk 

Hướng dẫn lập trình VBA để lấy dữ liệu từ website vào Excel với đối tượng QueryTable. Dữ liệu lấy dạng table có ID.

(*) Bài giảng lập trình VBA cơ bản: http://bluesofts.net/daotaothuchanh/l...(*) Mã nguồn: '-------CODE-------- 'Author: Nguyen Duy Tuan - http://bluesofts.netSub LayTableTuWeb() Dim qry As QueryTable Dim sh As Worksheet Dim CnnStr As String Set sh = ThisWorkbook.Sheets("Webtable") 'Xoa querytable truoc do XoaQT sh CnnStr = "URL;https://s.cafef.vn/Lich-su-giao-dich-..." Set qry = sh.QueryTables.Add(CnnStr, sh.Range("A5")) 'Query qry.WebSelectionType = xlSpecifiedTables qry.WebFormatting = xlWebFormattingNone qry.WebTables = """tblStats"",""tblData""" 'Tat ca cac table qry.Refresh 'Load du lieu End Sub Sub XoaQT(sh As Worksheet) Dim qry As QueryTable On Error Resume Next 'Bo qua loi For Each qry In sh.QueryTables qry.ResultRange.ClearContents 'Xoa data trong vung table qry.Delete 'Xoa QueryTable Next End Sub '------END COPY-------

0 nhận xét:

Đăng nhận xét