teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの掲載

2018/03/18 16:57

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -10,4 +10,85 @@
10
10
 
11
11
  どなたか,知っていらっしゃっる方はいませんか?
12
12
 
13
- 使用しているのは,Excel2016です。
13
+ 使用しているのは,Excel2016です。
14
+
15
+ [追記]
16
+ 情報が不足していました。すみません。
17
+
18
+ 書いてみたコードの中で,クエリに関する箇所は以下のようなものです。
19
+
20
+ ```VBA
21
+ Option Explicit
22
+
23
+ Sub Ten_mindata_output()
24
+
25
+ Dim i, j, celli As Integer
26
+ Dim titenmei, kenbangou, titenbangou as Integer
27
+ Dim year as Integer
28
+
29
+
30
+
31
+
32
+ For j = 1 to 53
33
+
34
+ Sheets("入力").Activate
35
+
36
+ titenmei = Cells(j,1).Value
37
+ kenbangou = Cells(j,2).Value
38
+ titenbangou = Cells(j,3).Value
39
+
40
+ For year = 2004 to 2017
41
+
42
+ Sheets("出力").Activate
43
+
44
+ celli = 1
45
+
46
+ For i = 1 To 30
47
+
48
+ With ActiveSheet.QueryTables.Add(Connection:= _
49
+ "URL;http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=" & kenbangou & "&block_no=" & titenbangou & "&year=" & year & "&month=04&day=" & i & "&view=p1" _
50
+ , Destination:=Range("$A$" & celli))
51
+ .Name = _
52
+ "10min_a1.php?prec_no=" & kenbangou & "&block_no="& titenbangou & "&year=" & year & "&month=04&day=" & i & "&view=p1"
53
+ .FieldNames = True
54
+ .RowNumbers = False
55
+ .FillAdjacentFormulas = False
56
+ .PreserveFormatting = True
57
+ .RefreshOnFileOpen = False
58
+ .BackgroundQuery = True
59
+ .RefreshStyle = xlInsertDeleteCells
60
+ .SavePassword = False
61
+ .SaveData = True
62
+ .AdjustColumnWidth = True
63
+ .RefreshPeriod = 0
64
+ .WebSelectionType = xlSpecifiedTables
65
+ .WebFormatting = xlWebFormattingNone
66
+ .WebTables = """tablefix1"""
67
+ .WebPreFormattedTextToColumns = True
68
+ .WebConsecutiveDelimitersAsOne = True
69
+ .WebSingleBlockTextImport = False
70
+ .WebDisableDateRecognition = False
71
+ .WebDisableRedirections = False
72
+ .Refresh BackgroundQuery:=False
73
+ End With
74
+
75
+ celli = celli + 147
76
+
77
+ DoEvents
78
+ DoEvents
79
+ DoEvents
80
+
81
+ Next i
82
+
83
+
84
+
85
+ Next year
86
+
87
+ Next j
88
+
89
+ End Sub
90
+
91
+ ```
92
+
93
+ この箇所は,以前マクロの記録を用いて作りました。
94
+ titenmei, kenbangou, titenbangouには,気象庁hpの各アメダス観測地点に対応した数字を代入していきます。