{"id":454,"date":"2018-04-16T05:47:39","date_gmt":"2018-04-16T05:47:39","guid":{"rendered":"http:\/\/mio-web.net\/pcsupport\/?p=454"},"modified":"2018-04-16T05:47:39","modified_gmt":"2018-04-16T05:47:39","slug":"access-vba%e3%80%80%e3%81%a7%e3%83%80%e3%82%a4%e3%82%a2%e3%83%ad%e3%82%b0%e3%83%9c%e3%83%83%e3%82%af%e3%82%b9%e3%82%92%e4%bd%bf%e3%81%84%e3%81%9f%e3%81%84%e6%99%82","status":"publish","type":"post","link":"https:\/\/mio-web.net\/pcsupport\/archives\/454\/","title":{"rendered":"ACCESS VBA\u3000\u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u4f7f\u3044\u305f\u3044\u6642"},"content":{"rendered":"<p>ACCESS VBA\u3000\u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u4f7f\u3044\u305f\u3044\u6642\u306b\u3001Microsoft Office Object Library\u3000\u3092\u53c2\u7167\u8a2d\u5b9a\u3067\u8ffd\u52a0\u3057\u3066Application.FileDialog(msoFileDialogOpen)\u3000\u3092\u7528\u3044\u305f\u5834\u5408\u3001\u4f5c\u6210\u5074\u3068\u4ed5\u69d8\u5074\u3067OFFICE\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u7570\u306a\u308b\u3068\u53c2\u7167\u8a2d\u5b9a\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3002\u30a8\u30af\u30bb\u30eb\u306e\u5834\u5408\u306b\u306fVBA\u306b\u3088\u3063\u3066\u5dee\u7570\u3092\u5438\u53ce\u3067\u304d\u308b\u304c\u3001Microsoft Office Object Library\u306e\u5834\u5408\u306b\u306f<br \/>\n\u96e3\u3057\u305d\u3046\u3060\u3063\u305f\u306e\u3067\u3001Microsoft Office Object Library\u306e\u4f7f\u7528\u306f\u3042\u304d\u3089\u3081\u3056\u308b\u3092\u3048\u306a\u304f\u306a\u3063\u305f\u3002\u304b\u308f\u308a\u306b\u3001API\u3092\u7528\u3044\u3066\u3001<br \/>\n\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u4f5c\u6210\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u3002<\/p>\n<p>Private Sub cmdEM_Click()*********************************<br \/>\n&#8216;\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u53c2\u7167\u3092\u53d6\u5f97 &#8211; Excel<br \/>\nDim strFolder As String<br \/>\nstrFolder = DLookup(&#8220;[\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9]&#8221;, &#8220;TB\u8a2d\u5b9a&#8221;)<\/p>\n<p>GetFileName = API_GetFileName1(strFolder)<\/p>\n<p>If GetFileName = &#8220;&#8221; Then<br \/>\n  Exit Sub<br \/>\nElse<br \/>\n  Set xls = CreateObject(&#8220;Excel.Application&#8221;)<br \/>\n  Set wkb2 = xls.Workbooks.Add(template:=GetFileName)<br \/>\nEnd If<\/p>\n<p>\u4ee5\u4e0b\u7701\u7565<\/p>\n<p>\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30eb********************************************<br \/>\nFunction API_GetFileName1(myFolder) As String<br \/>\n&#8216;WindowsAPI[\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f] \u30c0\u30a4\u30a2\u30ed\u30b0 \u30dc\u30c3\u30af\u30b9\u3092\u8868\u793a\u3059\u308b<\/p>\n<p>    Dim msaof As MSA_OPENFILENAME, ReturnType As Integer, N As Integer<\/p>\n<p>&#8216;\u25a0\u25a0\u25a0\u30c0\u30a4\u30a2\u30ed\u30b0 \u30dc\u30c3\u30af\u30b9\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a<br \/>\n    &#8216;\u2605\u30bf\u30a4\u30c8\u30eb\u30d0\u30fc\u306e\u6587\u5b57\u5217<br \/>\n    msaof.strDialogTitle = &#8220;\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044&#8221;<\/p>\n<p>    &#8216;\u2605\u30d5\u30a3\u30eb\u306e\u7a2e\u985e\u30b3\u30f3\u30dc\u306e\u8a2d\u5b9a<br \/>\n    msaof.strFilter = MSA_CreateFilterString _<br \/>\n    (&#8220;\uff83\uff9e\uff70\uff80\uff8d\uff9e\uff70\uff7d(*.mdb)&#8221;, &#8220;*.mdb;*mde&#8221;, &#8220;\u30c6\u30ad\u30b9\u30c8(*.txt)&#8221;, &#8220;*.txt&#8221;, &#8220;\u5168\u3066\u306e\u30d5\u30a1\u30a4\u30eb&#8221;, &#8220;*.*&#8221;)<\/p>\n<p>    &#8216;\u2605\u4f55\u3092\u53d6\u5f97\u3059\u308b\u304b\uff1f\u25c6\u958b\u304f\u30c0\u30a4\u30a2\u30ed\u30b0&#8211;\u30d5\u30eb\u30d1\u30b9\u21920, \u30db\u30eb\u30c0\u30fc\u30d1\u30b9\u21921, \u30d5\u30a1\u30a4\u30eb\u540d\u306e\u307f\u21922\u25c6<br \/>\n    &#8216;\u2605\u958b\u304f\u304b\uff1f\u4fdd\u5b58\u304b\uff1f\u25c6\u4fdd\u5b58\u30c0\u30a4\u30a2\u30ed\u30b0&#8211;\u30d5\u30eb\u30d1\u30b9\u21923, \u30db\u30eb\u30c0\u30fc\u30d1\u30b9\u21924, \u30d5\u30a1\u30a4\u30eb\u540d\u306e\u307f\u21925\u25c6<br \/>\n    ReturnType = 0<\/p>\n<p>    msaof.strInitialDir = myFolder           &#8216;\u521d\u671f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea,\u898f\u5b9a\u5024\u306f\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30fc<br \/>\n    msaof.lngFilterIndex = 3           &#8216;\u30d5\u30a1\u30a4\u30eb\u7a2e\u985e\u30b3\u30f3\u30dc\u306e\u4f55\u756a\u76ee\u3092\u6700\u521d\u306b\u8868\u793a\u3059\u308b\u304b<br \/>\n    &#8216;msaof.strInitialFile = &#8220;&#8221;          &#8216;\u30c0\u30a4\u30a2\u30ed\u30b0\u306b\u8868\u793a\u3055\u308c\u308b\u521d\u671f\u30d5\u30a1\u30a4\u30eb\u540d<br \/>\n    &#8216;msaof.strInitialDir = &#8220;&#8221;           &#8216;\u521d\u671f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea<br \/>\n    &#8216;msaof.strDefaultExtension = &#8220;*.mdb&#8221; &#8216;\u62e1\u5f35\u5b50\u3092\u7701\u3044\u3066\u8a18\u5165\u3057\u305f\u6642\u81ea\u52d5\u7684\u306b\u4ed8\u3051\u3089\u308c\u308b\u62e1\u5f35\u5b50<br \/>\n    msaof.lngFlags = OFN_HIDEREADONLY   &#8216;\u8aad\u307f\u53d6\u308a\u5c02\u7528\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u975e\u8868\u793a<br \/>\n&#8216;\u25a0\u25a0\u25a0\u8a2d\u5b9a\u306f\u3053\u3053\u307e\u3067<\/p>\n<p>&#8216;\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u958b\u304f\u30eb\u30fc\u30c1\u30f3<br \/>\n    Select Case ReturnType<br \/>\n        Case 3, 4, 5: MSA_GetSaveFileName msaof<br \/>\n        Case Else: MSA_GetOpenFileName msaof<br \/>\n    End Select<\/p>\n<p>&#8216;\u623b\u308a\u5024<br \/>\n    Select Case ReturnType<br \/>\n        Case 2, 5<br \/>\n            API_GetFileName1 = Trim(msaof.strFileNameReturned)<br \/>\n        Case 1, 4<br \/>\n            For N = 1 To Len(Trim(msaof.strFullPathReturned))<br \/>\n                If InStr(N, Trim(msaof.strFullPathReturned), &#8220;\\&#8221;) = 0 Then Exit For<br \/>\n            Next N<br \/>\n            API_GetFileName1 = Left(Trim(msaof.strFullPathReturned), N &#8211; 1)<br \/>\n        Case Else<br \/>\n            API_GetFileName1 = Trim(msaof.strFullPathReturned)<br \/>\n    End Select<br \/>\nEnd Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ACCESS VBA\u3000\u3067\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u4f7f\u3044\u305f\u3044\u6642\u306b\u3001Microsoft Office Object Library\u3000\u3092\u53c2\u7167\u8a2d\u5b9a\u3067\u8ffd\u52a0\u3057\u3066Application.FileDialog(msoFileDialogOpe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[24],"tags":[],"class_list":["post-454","post","type-post","status-publish","format-standard","hentry","category-access"],"_links":{"self":[{"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/posts\/454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/comments?post=454"}],"version-history":[{"count":1,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/posts\/454\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/posts\/454\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/media?parent=454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/categories?post=454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mio-web.net\/pcsupport\/wp-json\/wp\/v2\/tags?post=454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}