https://s.cafef.vn/screener.aspx#dataのURLからVBAでテーブルを取得したい。テーブルには HTML ファイルに埋め込まれた JSON データが含まれているため、この作業は困難ですが、Google Apps Scripts のカスタム関数の作成を手伝ってくれた GAS 専門家の田名池さんには親切でした。( IMPORTHTML() はこの Web ページ構造では機能しません) 関数は次のようになります。
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
const html = res.getContentText().match(/var jsonData \=([\S\s\w]+\}\])/);
if (!html) return "No tables. Please confirm URL again.";
const table = JSON.parse(html[1].replace(/\n/g, ""));
const header = ["", "FullName", "Symbol", "CenterName", "ChangePrice", "VonHoa", "ChangeVolume", "EPS", "PE", "Beta", "Price"];
return table.reduce((ar, e, i) => {
const temp = header.map(f => f == "" ? i + 1 : e[f]);
ar.push(temp);
return ar;
}, [header]); }
この関数は Google Sheets 環境で完璧に動作しますが、私の目標は VBA に変換することです。つまり、https://s.cafef.vn/screener.aspx#dataでテーブルを取得できる VBA モジュールを作成することです。 .
助けや提案をありがとう
曹操どれみ