マクロVBAで時系列データをExcelにロードする方法は?

このQ&Aのポイント
  • マクロVBAを使用して、特定のURLから時系列データをExcelにロードする方法について質問です。
  • Excelのシートに入力済みの銘柄コードと期間を指定し、VBAを使用して指定したURLからデータをロードします。
  • 選択した終了日までのデータをロードするため、URL中の選択終了日を変更する処理が必要です。しかし、それを行ってもデータが正常にロードされません。原因を教えてください。
回答を見る
  • ベストアンサー

マクロ VBA 簡単なことなのかもしれませんが?

時系列をexcelにロードする際、http://table.yahoo.co.jp/t?c=2007&a=6&b=20&f=2007&d=9&e=21&g=d&s=1321.o&y=0&z=1321.o のページの 月日から月日までの部分と銘柄コード=excelシート入力済。⇒VBA⇒ロードするための作業を、下記の方法で、とりあえず、終了日のところから改式をやってみたのですが、うまくゆきません。 "選択終了日"に変更する前の、数字の状態ではロードできるので、テーブル番号等は、問題ないようです。 原因の解る方、よろしくお願いします。 ----------------------------- Sub test() Range("a1:h300") = "" Dim shuuryoubi As String '選択終了日 Range("b1").Select With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://table.yahoo.co.jp/t?c=2007&a=6&b=20&f=2007&d=9&e=選択終了日&g=d&s=1321.o&y=0&z=1321.o" _ , Destination:=Range("b1")) .Name = _ "t?c=2007&a=6&b=20&f=2007&d=9&e=選択終了日&g=d&s=1321.o&y=0&z=1321.o" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "23" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False shuuryoubi = 17 End With End Sub

質問者が選んだベストアンサー

  • ベストアンサー
  • redfox63
  • ベストアンサー率71% (1325/1856)
回答No.1

URLの部分を t?c=2007&a=6&b=20&f=2007&d=9&e=" & shuuryoubi & "&g=d&s=1321.o&y=0&z=1321.o" といった具合に編集します # 行が分割されていますが1行で書くか _ を使って分割してください 最後のほうで代入している shuuryoubi = 17 は QueryTables.Add より前で実行しましょう

t-tommy
質問者

お礼

アドバイスありがとうございました^^。 全ての入力が可能になり、とても助かりました。 ちなみに、下記様になりました (同様の件で探されている方参考になさってください)。 Sub test77() Range("a1:h300") = "" Dim kaisituki As Integer '選択開始月 Dim kaisibi As Integer '選択開始日 Dim shuuryoutuki As Integer '選択終了月 Dim shuuryoubi As Integer '選択終了日 Dim sijyou As Integer '選択市場 Dim sijyoukigou As String '選択市場記号 Range("b1").Select kaisituki = 7 kaisibi = 21 shuuryoutuki = 8 shuuryoubi = 20 sijyou = 6363 sijyoukigou = t With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://table.yahoo.co.jp/t?c=2007&a=" & kaisituki & "&b=" & kaisibi & "&f=2007&d=" & shuuryoutuki & "&e=" & shuuryoubi & "&g=d&s=" & sijyou & "." & sijyoukigou & "&y=0&z=" & sijyou & "." & sijyoukigou & "" _ , Destination:=Range("b1")) .Name = _ "t?c=2007&a=" & kaisituki & "&b=" & kaisibi & "&f=2007&d=" & shuuryoutuki & "&e=" & shuuryoubi & "&g=d&s=" & sijyou & "." & sijyoukigou & "&y=0&z=" & sijyou & "." & sijyoukigou & """" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "23" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub

その他の回答 (1)

  • imogasi
  • ベストアンサー率27% (4737/17068)
回答No.2

私が間違ったかもしれませんが、#1のご回答を取り入れ、質問のコードをやってみましたが、シートにデータが出ませんでした。 別途 Sub test02() Range("a1:h300") = "" With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://table.yahoo.co.jp/t?c=2007&a=8&b=20&f=2007&d=9&e=17&g=d&s=7203.T&y=0&z=7203.T", _ Destination:=Range("a1")) .BackgroundQuery = True .TablesOnlyFromHTML = True .Refresh BackgroundQuery:=False .SaveData = True .AdjustColumnWidth = True End With End Sub でやると、シートにデータが取れました。 銘柄をトヨタ自動車に、また期間を変えました。 東証、大証のT,Oはどちらでも出ました。 質問のコードを#1で修正して、質問者さんの側で、データがシートに出れば、私の間違いです。本件無視してください。 もし質問者さんの側でやって、出ないなら、 (私は.QueryTables.Addの引数について詳しくないので)、質問者さんの側で、私の乗せた上記コードを参考に、引数を中心に原因を当たってください。

関連するQ&A

  • あと少しなんですが、時系列の次のページに関して

    yahoo時系列(http://table.yahoo.co.jp/t?c=2007&a=6&b=28&f=2007&d=9&e=29&g=d&s=1321.o&y=0&z=1321.o) にある、最初の50位までは下記で、できるのですが、51位以降のダウンロードができません。 Scripte Eitorで確認したところ、(1)(50位まで)が(2)(51位から)に変わる(最後に&x=.csvが追加されます)のですが、下記をどのように変更したらよいのか解りません。 わかる方、よろしくお願いします。 (1) http://table.yahoo.co.jp/t?c=2007&a=4&b=29&f=2007&d=9&e=29&g=d&s=8411.t&y=0&z=8411.t (3) http://table.yahoo.co.jp/t?s=8411.t&a=4&b=29&c=2007&d=9&e=29&f=2007&g=d&q=t&y=100&z=8411.t&x=.csv ----------------------------- Dim kaisituki As Integer '選択開始月 Dim kaisibi As Integer '選択開始日 Dim shuuryoutuki As Integer '選択終了月 Dim shuuryoubi As Integer '選択終了日 Dim sijyou As Integer '選択市場 Dim sijyoukigou As String '選択市場記号 Range("d3").Select kaisituki = Range("b3") kaisibi = Range("b4") shuuryoutuki = Range("b5") shuuryoubi = Range("b6") sijyou = Range("b7") sijyoukigou = Range("b8") With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://table.yahoo.co.jp/t?c=2007&a=" & kaisituki & "&b=" & kaisibi & "&f=2007&d=" & shuuryoutuki & "&e=" & shuuryoubi & "&g=d&s=" & sijyou & "." & sijyoukigou & "&y=0&z=" & sijyou & "." & sijyoukigou & "" _ , Destination:=Range("d3")) .Name = _ "t?c=2007&a=" & kaisituki & "&b=" & kaisibi & "&f=2007&d=" & shuuryoutuki & "&e=" & shuuryoubi & "&g=d&s=" & sijyou & "." & sijyoukigou & "&y=0&z=" & sijyou & "." & sijyoukigou & """" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "23" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With

  • VBAでWebクエリにて情報を自動収集するプログラム

    自動売買ロボット作成マニュアルという本を買いました。 これは株などを自動売買するプログラムを作るための方法が書いた本です。(言語はエクセルに搭載されてあるVBAというプログラム言語です) そのプログラムを作る過程で、まずYahoo!ファイナンスから株価などの情報を10年分自動収集するプログラムを作ったのですが、「インターネットサーバーに接続できません」と出て、きちんと実行できません。 そこで、デバックをすると.Refresh BackgroundQuery:=Falseというプログラムのところがチェックされました。どうしたらいいでしょうか? この文章だけでは対処できないと思いますのでプログラムを書いておきます。長々とお読みいただきありがとうございます。どうかお知恵をお貸しください。 Dim url As String Dim lastrow As Integer Dim i As Integer Sub Get_Data() With ActiveSheet.QueryTables.Add(Connection:=url, Destination:=Cells(lastrow, 2)) .Name = _ "t?s=998407.o&a=4&b=22&c=2008&d=7&e=24&f=2008&g=d&q=t&y=0&z=998407.o&x=_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "19" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub Sub Calc() Dim code As String Dim data_length As Integer, date_temp As Date Dim day_s As Integer, month_s As Integer, year_s As Integer Dim day_e As Integer, month_e As Integer, year_e As Integer Dim row_length As Integer code = "998407.o" data_length = -3650 date_temp = DateAdd("d", data_length, Now) day_e = Day(Now) month_e = Month(Now) year_e = Year(Now) day_s = Day(date_temp) month_s = Month(date_temp) year_s = Year(date_temp) Range("B4:H65000").ClearContents For i = 0 To Abs(data_length) * 0.65 Step 50 url = "URL; http://table.yahoo.co.jp/t?s=" & code & "&a=" & month_s & "&b=" & day_s & "&c=" & year_s & "&d=" & month_e & "&e=" & day_e & "&f=" & year_e & "&g=d&q=t&y=" & i & "&z=" & code & "&x=.csv" If i = 0 Then lastrow = "4" Call Get_Data If Range("B4") = "" Then Exit Sub End If Else lastrow = (Range("B4").End(xlDown).Row + 1) Call Get_Data Range("B" & lastrow, "H" & lastrow).Delete row_length = (Range("B4").End(xlDown).Row) If row_length - lastrow < 49 Then Exit For End If End If Next Range("B5:H65000").Sort Key1:=Columns("B") lastrow = Range("B4").End(xlDown).Row Range("B5", "B" & lastrow).NumberFormatLocal = "yyyy/mm/dd" Range("C5", "H" & lastrow).NumberFormatLocal = "0" Range("A1").Select End Sub

  • VBAの追加

    同じ様な場所からデータを取り出す時、欲しい情報はWebTables="5"でK3に「5」を入力しておきますが、たまに1つか2つくらい場所違いにより欲しい情報はWebTables="4"の時が存在します。 l3(エル3)に「4」を入力しておいて、WebTables =5に欲しくない情報が入っている場合はWebTables =4を使用するという命令を追加したいと思います。 下記右側のようにセルに「メーカー」の文字が入っていればそのままWebTables =5を使い、「メーカー」の文字が入っていなければWebTables =4を実行 と考えております。 また、それ以外の方法でも構いませんのでお願い致します。 Dim i As Long Dim myAddress As String lastrow = ActiveSheet.Range("A3").End(xlDown).Row d = 50 For i = 3 To lastrow myAddress = Range("B" & i).Value Dim bbb As String bbb = Range("K3").Value With ActiveSheet.QueryTables.Add(Connection:= _ "URL;" & myAddress, Destination:=Range("B" & d + 1)) .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "" & bbb .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With d = Range("B65536").End(xlUp).Row Next i                     WebTables =5の場合                     正しく欲しい情報                     111111111111111111         メーカー1111111111                     111111111111111111     →   11111111111111111                     111111111111111111         11111111111111111 WebTables =4の場合 正しく欲しい情報      欲しくない情報が入っている 111111111111111111     222222222222222222 111111111111111111     222222222222222222 111111111111111111     222222222222222222

  • 「Excel VBA」 Webクエリ マクロ「実行時エラー"1004"ファイルにアクセスできませんでした」

    Webクエリを使って、「Yahooファイナンス」から日経平均株価の時系列データを取得したいのですが、うまくいきません。(TT) 下記に全コードを記載しますので、ご回答よろしくお願いします。 Dim url As String Dim lastrow As Integer Dim i As Integer Sub Calc() '価格データを取得するマクロ 'このマクロ内で用いる各変数を宣言 Dim code As String Dim day_s As Integer, month_s As Integer, year_s As Integer Dim day_e As Integer, month_e As Integer, year_e As Integer Dim row_length As Integer '変数に各値を代入 code = "998407.o" '株価コード day_e = 31 '取得終了日 month_e = 12 '取得終了月 year_e = 2005 '取得終了年 day_s = 1 '取得開始日 month_s = 1 '取得開始月 year_s = 2005 '取得開始年 '価格データを取得 For i = 0 To 365 * 0.65 Step 50 '変数にURLを代入 url = "URL;http://table.yahoo.co.jp/t?s=" & code & "&a=" & month_s & "&b=" & day_s & "&c=" & year_s & "&d=" & month_e & "&e=" & day_e & "&f=" & year_e & "&g=d&q=t&y=" & i & "&z=" & code & "&x=.csv" '1回目の繰り返しの場合 If i = 0 Then lastrow = "4" Call Get_Data '価格データが取得できなかった場合、マクロを終了させる     If Range("B4") = "" Then Exit Sub End If '2回目以降の繰り返しの場合 Else lastrow = Range("B4").End(xlDown).Row + 1 Call Get_Data '見出しのセルを削除 Range("B" & lastrow, "H" & lastrow).Delete row_length = Range("B4").End(xlDown).Row '価格データが取得期間分存在していなかった場合、その時点で繰り返しを終了させる If row_length - lastrow < 49 Then Exit For End If End If Next End Sub Sub Get_Data() With ActiveSheet.QueryTables.Add(Connection:=url, Destination:=Cells(lastrow, 2)) .Name = "t?s=998407.o&g=d" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "22" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Range("B5:F54").Select Selection.Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _ :=xlPinYin, DataOption1:=xlSortNormal End Sub Calcマクロを実行すると、  「実行時エラー"1004"ファイルにアクセスできませんでした。次のいずれかを行ってください。」 というエラーが出て止まってしまいます。 デバッグをすると、「Get_Dataマクロ」内の、 .Refresh BackgroundQuery:=False が黄色になります。 ステップインしても、やっぱり、 .Refresh BackgroundQuery:=False の所でエラーが出ます。(TT) どうしても解決したい内容なので、 少しでも「解決の可能性」があれば、なんでも試してみたいと思っていますので、どうぞお気軽に回答お願いします。 力を貸しください。よろしくお願いします。

  • データのある所まで指定したい

    下記のようにB3からB80までマクロ実行できる様に設定しておきます。 例えばB38までしかデータがない場合、B39でデバッグになってしまいます。 データの入っている所まで実行できるようにお願い致します。 e = 70 ***************************************************** Dim y3 As String y3 = Range("B3").Value Dim cp3 As String cp3 = Range("P3").Value With ActiveSheet.QueryTables.Add(Connection:= _ "URL;" & y3, Destination:=Range("E" & e + 1)) .Name = "000" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "" & cp3 .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With e = Range("E65536").End(xlUp).Row ******************************************************      ・      ・      ・ ****************************************************** Dim y80 As String y80 = Range("B80").Value Dim cp80 As String cp80 = Range("P80").Value With ActiveSheet.QueryTables.Add(Connection:= _ "URL;" & y80, Destination:=Range("E" & e + 1)) .Name = "000" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "" & cp80 .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With e = Range("E65536").End(xlUp).Row ********************************************************

  • VBAでオーバーフローが出て困っています(エクセル2000です)

    自動売買ロボット作成マニュアルという本のなかに株価をダウンロードするためのプログラムとしてソースが書かれているのですが、オーバーフローとなってしまい、実行できません。lastrow = (Range("B4").End(xlDown).Row + 1)のところでオーバーフローを起こします。この文章だけでは対処できないと思いますのでプログラムを写します。 恐れ入りますが、お助けください。 Sub Calc() Dim code As String Dim data_length As Integer, date_temp As Date Dim day_s As Integer, month_s As Integer, year_s As Integer Dim day_e As Integer, month_e As Integer, year_e As Integer Dim row_length As Integer code = input_temp(2) data_length = -100 date_temp = DateAdd("d", data_length, Now) day_e = Day(Now) month_e = Month(Now) year_e = Year(Now) day_s = Day(date_temp) month_s = Month(date_temp) year_s = Year(date_temp) Range("B4:R65000").ClearContents For i = 0 To Abs(data_length) * 0.65 Step 50 If i = 0 Then lastrow = "4" For wtbl = 19 To 25 url = "URL;http://table.yahoo.co.jp/t?s=" & code & "&a=" & month_s & "&b=" & day_s & "&c=" & year_s & "&d=" & month_e & "&e=" & day_e & "&f=" & year_e & "&g=d&q=t&y=" & i & "&z=" & code & "&x=.csv" Call Get_Data If Range("B4") = "日付" Then Exit For Else Range("B4:H54").ClearContents End If Next Else url = "URL;http://table.yahoo.co.jp/t?s=" & code & "&a=" & month_s & "&b=" & day_s & "&c=" & year_s & "&d=" & month_e & "&e=" & day_e & "&f=" & year_e & "&g=d&q=t&y=" & i & "&z=" & code & "&x=.csv" lastrow = (Range("B4").End(xlDown).Row + 1) Call Get_Data Range("B" & lastrow, "H" & lastrow).Delete row_length = (Range("B4").End(xlDown).Row) If row_length - lastrow < 49 Then Exit For End If End If Next Range("B5:H65000").Sort Key1:=Range("B5") lastrow = Range("B4").End(xlDown).Row Range("B5", "B" & lastrow).NumberFormatLocal = "yyyy/mm/dd" Range("C5", "H" & lastrow).NumberFormatLocal = "0" Range("A1").Select End Sub Sub Get_Data() With ActiveSheet.QueryTables.Add(Connection:=url, Destination:=Cells(lastrow, 2)) .Name = "Yahoo" .FieldNames = False .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = wtbl .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .Refresh BackgroundQuery:=False End With End Sub

  • このマクロ処理をVBAにしたいのですが…

    テキストファイル→Excelへの取込み処理をVBAで記述したいのですが、上手く行きません。どなたか、ご存知の方いらっしゃいましたらご回答よろしくお願いします。 マクロ処理で試すとこんなカンジなのですが… With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\temp\S5097.txt", _ Destination:=Range("A3")) .Name = "SXXXX" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 932 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "|" .TextFileColumnDataTypes = Array(1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End Sub

  • Excelの三つのVBAを一つにまとめる。

     初めまして、よろしくお願いします。当方全くの素人でVBAの基礎もよくわからず、ネットから拾ってきていじった三つのVBAがあります。この三つ、一つ一つは個別に機能するのですが、VBAとして正しいのかさえよく解っていません。この三つを一つにまとめて、同時に機能するようにしたいと頭を抱えています。 Sub TEST() Application.ScreenUpdating = False Application.EnableEvents = False ActiveSheet.Calculate Range("b10:b20").Insert shift:=xlShiftToRight Range("b10:b20").Value = Range("a10:a20").Value Application.OnTime TimeValue("09:00:00"), "TEST" Application.ScreenUpdating = True Application.EnableEvents = True ActiveWorkbook.Save End Sub ________________________________________________________________ Sub TEST1() Application.ScreenUpdating = False Application.EnableEvents = False ActiveSheet.Calculate Dim myCnt As Long Range("c30:c40").Copy Range("d30:d40").PasteSpecial Paste:=xlPasteValues Range("b30:b40").Copy Range("c30:c40").PasteSpecial Paste:=xlPasteValues Range("a30:a40").Copy Range("b30:b40").PasteSpecial Paste:=xlPasteValues nextTime = Now() + TimeValue("01:00:00") Application.OnTime nextTime, "TEST1" Application.ScreenUpdating = True Application.EnableEvents = True ActiveSheet.Calculate ActiveWorkbook.Save End Sub ________________________________________________________________ Sub TEST2() Application.ScreenUpdating = False Application.EnableEvents = False ActiveSheet.Calculate Dim myCnt As Long Range("c50:c60").Copy Range("d50:d60").PasteSpecial Paste:=xlPasteValues Range("b50:b60").Copy Range("c50:c60").PasteSpecial Paste:=xlPasteValues Range("a50:a60").Copy Range("b50:b60").PasteSpecial Paste:=xlPasteValues nextTime = Now() + TimeValue("00:10:00") Application.OnTime nextTime, "TEST2" Application.ScreenUpdating = True Application.EnableEvents = True ActiveSheet.Calculate ActiveWorkbook.Save End Sub ________________________________________________________________  解る方、よろしくお願いします。

  • エクセルVBA URLの記述をセル参照に

    VBA初心者です。WEBクエリの作業をマクロで記録したものを編集しています。 そこで、コードのURL部分をセル参照にしたいのですが、コンパイルエラーが出るため記述が間違っているようです。もともとが間違っているのかどうかもわからず、その点につきまして、ご教授をお願い申し上げます。 Connection:="URL;http://www.○○○○" ↓編集 (URLを入れているセルは、Sheet1のA1、データを返すのはSheet2のA1) Connection:="ActiveWorkbook.WorkSheets("Sheet1").Range("A1")" "Sheet1"部分が選択された状態でエラーとなります。 以下は、ソースです。 Sub test1() With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://www.○○○○", Destination:=Range _ ("$A$1")) .Name = "151" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "22" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub

  • Excel VBA 【QueryTables.Add】について

    おしえてください。 マクロの自動記録で、外部からのデータ取り込みをしましたら 以下の様になりました。 With ActiveSheet.QueryTables.Add(Connection:= _ "○○;■■;●●;;□□;▲▲", Destination:=Range("A1")) .CommandText = Array("SELECT * FROM △△.▽▽") .Name = "☆☆ からのクエリ" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .Refresh BackgroundQuery:=False End With このコードについて勉強したくてヘルプやネットで調べましたが どうしても「.Name …」以降の説明がみつかりません; 詳しく説明の載っているサイトもしくは本などご存じでしたら 教えていただけないでしょうか。 よろしくお願い致します。

専門家に質問してみよう