{"id":65,"date":"2021-03-06T07:55:18","date_gmt":"2021-03-05T22:55:18","guid":{"rendered":"http:\/\/192.168.0.97\/bibouroku\/2021\/03\/06\/accessexcel\/"},"modified":"2021-03-06T07:55:18","modified_gmt":"2021-03-05T22:55:18","slug":"accessexcel","status":"publish","type":"post","link":"https:\/\/www.donijan.com\/bibouroku\/2021\/03\/accessexcel.html","title":{"rendered":"Access\u3068Excel\u3068\u306e\u9023\u643a"},"content":{"rendered":"<p>\u9ad8\u901f\u3067\u30a2\u30af\u30bb\u30b9\u3068\u30a8\u30af\u30bb\u30eb\u3068\u306e\u30c7\u30fc\u30bf\u3092\u3084\u308a\u3068\u308a\u3059\u308b\u65b9\u6cd5<\/p>\n<p>\u63a5\u7d9a\u8a2d\u5b9a\u3068\u5909\u6570\u3078\u306e\u66f8\u304d\u8fbc\u307f<\/p>\n<p>\u5909\u6570\u304b\u3089\u30a8\u30af\u30bb\u30eb\u3078\u306e\u914d\u5217\u66f8\u304d\u8fbc\u307f\u306e<\/p>\n<p>\u5099\u5fd8\u9332<\/p>\n<p><!--more--><\/p>\n<p>&#8216;\u3053\u3053\u304b\u3089\u306faccess\u3078\u306e\u63a5\u7d9a\u306e\u5206\u3001\u5909\u6570\u5ba3\u8a00<br \/>Dim cn As ADODB.Connection &#8216;\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u5ba3\u8a00<br \/>Dim rs As ADODB.Recordset &#8216;\u30ec\u30b3\u30fc\u30c9\u8a2d\u5b9a\u306e\u5ba3\u8a00<br \/>Dim aTblnm As String &#8216;\u30c7\u30fc\u30bf\u3092\u62bd\u51fa\u3059\u308bSQL\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8<br \/>Dim Row1 As Long &#8216;sheet\u306b\u66f8\u304d\u8fbc\u3080\u884c\u6570<br \/>Dim Datval() As Variant<\/p>\n<p>Row1 = 1<br \/>aTblnm = TblName &#8216;\u30c6\u30fc\u30d6\u30eb\u540d<br \/>aTblPath = DbPath &amp; &#8220;\\&#8221; &amp; DbName<\/p>\n<p>Set cn = New Connection<\/p>\n<p>cn.ConnectionString = &#8220;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&#8221; &amp; aTblPath<\/p>\n<p>&#8216;**********************************************************************<\/p>\n<p>cn.Open &#8216;\u63a5\u7d9a\u5ba3\u8a00 Order<\/p>\n<p>&#8216;*******************************************************************************<\/p>\n<p>Selcmd = fnAcPrtSelectSQL(TblName, Kb, Zkb, Stymd, Enymd, Skb) &#8216;Select\u306eSQL<\/p>\n<p>Set rs = New Recordset<br \/> rs.Open Selcmd, cn, CursorType:=adOpenStatic<\/p>\n<p> If rs.EOF = True Then<br \/> fnAcTukiShukei = 0<br \/> Else<br \/> &#8216;\u518d\u914d\u5217\u5ba3\u8a00<br \/> ReDim Preserve Datval(0 To rs.RecordCount, 0 To rs.Fields.Count)<br \/> With Sheets(Shnm)<br \/> For col = 0 To rs.Fields.Count &#8211; 1<br \/> Datval(0, col + 1) = rs.Fields(col).Name<br \/> Next col<\/p>\n<p> rs.MoveFirst<\/p>\n<p> Do Until rs.EOF<br \/> For col = 0 To rs.Fields.Count &#8211; 1<br \/> Select Case col<br \/> Case Is &gt; 5<br \/> .Cells(Row1, col + 1).NumberFormatLocal = &#8220;#,##0&#8221; &#8216;\u66f8\u5f0f\u8a2d\u5b9a\u3092\u3057\u305f\u3044\u30bb\u30eb\u3060\u3051\u30bb\u30c3\u30c8<br \/> End Select<br \/> Datval(Row1, col + 1) = rs.Fields(col)<\/p>\n<p>Next col<br \/> Row1 = Row1 + 1<br \/> rs.MoveNext<\/p>\n<p> Loop<br \/> End With<br \/> End If<\/p>\n<p>Sheets(Shnm).Range(Cells(2, 1), Cells(rs.RecordCount + 2, rs.Fields.Count + 1)) = Datval<\/p>\n<p>Set rs = Nothing<br \/>&#8216;\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306e\u5f8c\u51e6\u7406\u3092\u3059\u308b<\/p>\n<p>&#8216;*******************************************************************************<br \/>&#8216;\u30ec\u30b3\u30fc\u30c9\u30bb\u30c3\u30c8\u306a\u3069\u306e\u5f8c\u51e6\u7406\u3092\u3059\u308b<\/p>\n<p>cn.Close<br \/>Set cn = Nothing<\/p>\n<p>End Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ad8\u901f\u3067\u30a2\u30af\u30bb\u30b9\u3068\u30a8\u30af\u30bb\u30eb\u3068\u306e\u30c7\u30fc\u30bf\u3092\u3084\u308a\u3068\u308a\u3059\u308b\u65b9\u6cd5 \u63a5\u7d9a\u8a2d\u5b9a\u3068\u5909\u6570\u3078\u306e\u66f8\u304d\u8fbc\u307f \u5909\u6570\u304b\u3089\u30a8\u30af\u30bb\u30eb\u3078\u306e\u914d\u5217\u66f8\u304d\u8fbc\u307f\u306e \u5099\u5fd8\u9332<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,16,17],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-access","category-excel","category-vba"],"_links":{"self":[{"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":0,"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donijan.com\/bibouroku\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}