質問編集履歴

1

コードの掲載

2018/03/18 16:57

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,165 @@
23
23
 
24
24
 
25
25
  使用しているのは,Excel2016です。
26
+
27
+
28
+
29
+ [追記]
30
+
31
+ 情報が不足していました。すみません。
32
+
33
+
34
+
35
+ 書いてみたコードの中で,クエリに関する箇所は以下のようなものです。
36
+
37
+
38
+
39
+ ```VBA
40
+
41
+ Option Explicit
42
+
43
+
44
+
45
+ Sub Ten_mindata_output()
46
+
47
+
48
+
49
+ Dim i, j, celli As Integer
50
+
51
+ Dim titenmei, kenbangou, titenbangou as Integer
52
+
53
+ Dim year as Integer
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ For j = 1 to 53
64
+
65
+
66
+
67
+ Sheets("入力").Activate
68
+
69
+
70
+
71
+ titenmei = Cells(j,1).Value
72
+
73
+ kenbangou = Cells(j,2).Value
74
+
75
+ titenbangou = Cells(j,3).Value
76
+
77
+
78
+
79
+ For year = 2004 to 2017
80
+
81
+
82
+
83
+ Sheets("出力").Activate
84
+
85
+
86
+
87
+ celli = 1
88
+
89
+
90
+
91
+ For i = 1 To 30
92
+
93
+
94
+
95
+ With ActiveSheet.QueryTables.Add(Connection:= _
96
+
97
+ "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" _
98
+
99
+ , Destination:=Range("$A$" & celli))
100
+
101
+ .Name = _
102
+
103
+ "10min_a1.php?prec_no=" & kenbangou & "&block_no="& titenbangou & "&year=" & year & "&month=04&day=" & i & "&view=p1"
104
+
105
+ .FieldNames = True
106
+
107
+ .RowNumbers = False
108
+
109
+ .FillAdjacentFormulas = False
110
+
111
+ .PreserveFormatting = True
112
+
113
+ .RefreshOnFileOpen = False
114
+
115
+ .BackgroundQuery = True
116
+
117
+ .RefreshStyle = xlInsertDeleteCells
118
+
119
+ .SavePassword = False
120
+
121
+ .SaveData = True
122
+
123
+ .AdjustColumnWidth = True
124
+
125
+ .RefreshPeriod = 0
126
+
127
+ .WebSelectionType = xlSpecifiedTables
128
+
129
+ .WebFormatting = xlWebFormattingNone
130
+
131
+ .WebTables = """tablefix1"""
132
+
133
+ .WebPreFormattedTextToColumns = True
134
+
135
+ .WebConsecutiveDelimitersAsOne = True
136
+
137
+ .WebSingleBlockTextImport = False
138
+
139
+ .WebDisableDateRecognition = False
140
+
141
+ .WebDisableRedirections = False
142
+
143
+ .Refresh BackgroundQuery:=False
144
+
145
+ End With
146
+
147
+
148
+
149
+ celli = celli + 147
150
+
151
+
152
+
153
+ DoEvents
154
+
155
+ DoEvents
156
+
157
+ DoEvents
158
+
159
+
160
+
161
+ Next i
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+ Next year
170
+
171
+
172
+
173
+ Next j
174
+
175
+
176
+
177
+ End Sub
178
+
179
+
180
+
181
+ ```
182
+
183
+
184
+
185
+ この箇所は,以前マクロの記録を用いて作りました。
186
+
187
+ titenmei, kenbangou, titenbangouには,気象庁hpの各アメダス観測地点に対応した数字を代入していきます。