{"id":568,"date":"2016-11-12T22:14:19","date_gmt":"2016-11-12T13:14:19","guid":{"rendered":"http:\/\/rgm79sf.asuscomm.com\/wordpress\/?p=568"},"modified":"2018-07-09T22:10:47","modified_gmt":"2018-07-09T13:10:47","slug":"vba%e3%81%ab%e6%8c%91%e6%88%a6%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.rgm79sf.site\/?p=568","title":{"rendered":"VBA\u306b\u6311\u6226\uff01"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30b8\u30e0\u3067\u3059\u3002<\/p>\n<p>\u4eca\u65e5\u306e\u6388\u696d\u3067\u3053\u3093\u306a\u8ab2\u984c\u304c\u51fa\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h3>Excel VBA\u3067CSV\u5f62\u5f0f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308c\uff01\uff01<\/h3>\n<p>\u3067\u3059\u3063\u3066\u3002<\/p>\n<p>\u3075\u3080\u3002\u305d\u3082\u305d\u3082VBA\u3063\u3066\u4f55\u3088\u3063\u3066\u3068\u3053\u308d\u304b\u3089\u59cb\u307e\u308b\u306e\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>VBA\u3068\u306f\u3001<strong>Visual Basic for Applications<\/strong>\u306e\u7565\u3089\u3057\u3044\u3002<\/p>\n<p>\u3053\u308c\u306fMicrosoft\u306eoffice\u30b7\u30ea\u30fc\u30ba\u306b\u6a19\u6e96\u642d\u8f09\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u306e\u3053\u3068\u3002<\/p>\n<p>\u8981\u306fVBA\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u66f8\u3051\u308b\u3068office\u30b7\u30ea\u30fc\u30ba\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3067\u304d\u308b\u306e\u3067\u3059\u306a\u3002\u81ea\u5206\u306e\u3084\u308a\u305f\u3044\u4f5c\u696d\u3092\u81ea\u52d5\u5316\u3067\u304d\u308b\u3001\u3068\u3002<\/p>\n<p>\u4fbf\u5229\u3067\u3059\u306a\u3002<\/p>\n<p>VBA\u306f\u5206\u304b\u3063\u305f\u3002\u6b21\u306b\u51fa\u3066\u304f\u308bCSV\u5f62\u5f0f\u3063\u3066\u306a\u3093\u305e\u3084\u3002<\/p>\n<p>CSV\u30d5\u30a1\u30a4\u30eb\u3068\u306f\u3001\u5024\u3092\u30ab\u30f3\u30de\u3067\u533a\u5207\u3063\u3066\u66f8\u3044\u305f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u3053\u3068<\/p>\n<p>\u30fb\u30fb\u30fb\u3078\u30fc\u3002<\/p>\n<p>Excel\u3067\u7c21\u5358\u306b\u66f8\u304d\u51fa\u305b\u308b\u3089\u3057\u3044\u306e\u3067\u3084\u3063\u3066\u307f\u3088\u3046\u3002<\/p>\n<p>\u4eca\u56de\u306foffice2016\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305aExcel\u3067\u3053\u3093\u306a\u8868\u3092\u4f5c\u3063\u3066\u307f\u305f\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 108pt;\" border=\"0\" width=\"144\" cellspacing=\"0\" cellpadding=\"0\">\n<colgroup>\n<col style=\"width: 54pt;\" span=\"2\" width=\"72\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 18.75pt;\">\n<td style=\"height: 18.75pt; width: 54pt;\" width=\"72\" height=\"25\">X<\/td>\n<td style=\"width: 54pt;\" width=\"72\">Y<\/td>\n<\/tr>\n<tr style=\"height: 18.75pt;\">\n<td style=\"height: 18.75pt;\" align=\"right\" height=\"25\">1<\/td>\n<td align=\"right\">2<\/td>\n<\/tr>\n<tr style=\"height: 18.75pt;\">\n<td style=\"height: 18.75pt;\" align=\"right\" height=\"25\">3<\/td>\n<td align=\"right\">4<\/td>\n<\/tr>\n<tr style=\"height: 18.75pt;\">\n<td style=\"height: 18.75pt;\" align=\"right\" height=\"25\">5<\/td>\n<td align=\"right\">6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3044\u3064\u3082\u306eExcel\u3067\u3059\u306a\u3002<\/p>\n<p>\u3053\u308c\u3092CSV\u5f62\u5f0f\u3067\u66f8\u304d\u51fa\u3057\u305f\u3082\u306e\u3092\u898b\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb\uff1f<\/p>\n<p>\u3042\u3001\u3053\u306e\u6642\u306bExcel\u3067\u306f\u306a\u304f\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u958b\u304d\u307e\u3059\u3002<\/p>\n<h3 style=\"text-align: left;\">X,Y<br \/>\n1,2<br \/>\n3,4<br \/>\n5,6<\/h3>\n<p>&nbsp;<\/p>\n<p>\u672c\u5f53\u306b\u30ab\u30f3\u30de\u3067\u533a\u5207\u3089\u308c\u3066\u30fc\u3089\u3002<\/p>\n<p>\u30fb\u30fb\u30fb\u3053\u306e\u5f62\u5f0f\u3092\u8aad\u307f\u53d6\u3063\u3066\u30b0\u30e9\u30d5\u4f5c\u308b\u3093\uff1f<\/p>\n<p>\u51fa\u6765\u308b\u304b\u306a\u30fc\u3002<\/p>\n<p>Microsoft office\u3068\u3044\u3046\u3053\u3068\u3067google\u3067\u8abf\u3079\u308c\u3070\u3044\u308d\u3044\u308d\u306a\u60c5\u5831\u304c\u8ee2\u304c\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u53e4\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3060\u3063\u305f\u308a\u3001\u5168\u7136\u9055\u3046\u3053\u3068\u306b\u306a\u3063\u305f\u308a\u3068\u3001\u5fc5\u8981\u306a\u60c5\u5831\u3092\u5f97\u308b\u306e\u306b\u82e6\u52b4\u3057\u307e\u3059\u30fb\u30fb\u30fb<\/p>\n<p>\u6c17\u3092\u53d6\u308a\u76f4\u3057\u3066\u3001VBA\u3092\u5f04\u3063\u3066\u307f\u307e\u3059\u3002\u3068\u308a\u3042\u3048\u305a\u65b0\u3057\u3044\u4e8b\u3059\u308b\u3068\u304d\u306fHello World\u304b\u3089\u3063\u3066\u8ab0\u304b\u304c\u8a00\u3063\u3066\u305f\uff01<\/p>\n<p>\u305d\u3093\u306a\u8a33\u3067Hello World\u3057\u3066\u307f\u3088\u3046\u3002<\/p>\n<p>\u307e\u305aVBA\u306e\u30a8\u30c7\u30a3\u30bf\u3092\u958b\u304f\u3002\u3053\u308c\u306f\u4eca\u56de\u306fExcel\u306e\u958b\u767a\u30bf\u30d6(\u30aa\u30d7\u30b7\u30e7\u30f3\u304b\u3089\u8868\u793a\u3059\u308b)\u304b\u3089Visual Basic\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u958b\u59cb\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u5de6\u5074\u306eSheet1\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\uff08\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u4e8b\u3002\u4e00\u5ea6\u8a00\u3063\u3066\u307f\u305f\u304b\u3063\u305f\u3060\u3051\uff09\u958b\u59cb\u306a\u308a\u3002<\/p>\n<p>\u3084\u308b\u4e8b\u306f\u7c21\u5358\u3002Hello World\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>VBA\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u51fa\u529b\u95a2\u6570\u306fMsgBox\u3068\u3044\u3046\u3084\u3064\u3089\u3057\u3044\u3002<\/p>\n<p>\u305d\u3093\u3067\u30b3\u30fc\u30c9\u306e\u59cb\u307e\u308a\u306fSub \u95a2\u6570\u540d()<\/p>\n<p>\u7d42\u308f\u308a\u306f\u3000End sub<\/p>\n<p>\u3068\u3044\u3046\u6c7a\u307e\u308a\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u3060\u3051\u306e\u60c5\u5831\u3067Hello World\u3057\u3066\u307f\u308b<\/p>\n<p>\u30b3\u30fc\u30c9<\/p>\n<p>Sub hello()<br \/>\nMsgBox &#8220;Hello World!&#8221;<br \/>\nEnd Sub<\/p>\n<p>\u5b9f\u884c\u3059\u308b\u306b\u306f\u5de6\u4e0a\u3089\u3078\u3093\u306b\u3042\u308b\u518d\u751f\u30de\u30fc\u30af\u3002\u3000\u30dd\u30c1\u30c3\u3068\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u51fa\u6765\u305f!\u3000\u3000\u3053\u308c\u3067\u52dd\u3064\u308b\u3002<\/p>\n<p>\u3055\u3066\u3055\u3066\u6b21\u306f\u306fCSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3001\u30bb\u30eb\u306b\u66f8\u304d\u51fa\u3057\u3066<\/p>\n<p>\u305d\u306e\u30c7\u30fc\u30bf\u3092\u3082\u3068\u306b\u30b0\u30e9\u30d5\u3092\u4f5c\u3063\u3066\u3082\u3089\u3044\u307e\u3059\u3002<\/p>\n<p>\u3055\u3063\u304d\u4f5c\u3063\u305f\u8868\u3092\u57fa\u306b\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b0\u30fc\u30b0\u30eb\u5148\u751f\u3068\u6388\u696d\u306e\u8cc7\u6599\u3092\u5143\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\uff01<\/p>\n<p>\u4ee5\u4e0b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<br \/>\nSub graph()<br \/>\nDim varFileName As Variant<br \/>\nDim intFree As Integer<br \/>\nDim strRec As String<br \/>\nDim strSplit() As String<br \/>\nDim i As Long, j As Long<\/p>\n<p>\u2019\u3053\u3053\u307e\u3067\u95a2\u6570\u306e\u5ba3\u8a00<\/p>\n<p>varFileName = Application.GetOpenFilename(&#8220;CSV\u30d5\u30a1\u30a4\u30eb,*.csv&#8221;)<\/p>\n<p>\u2019CSV\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3057\u3066\u958b\u304f\u30c0\u30a4\u30a2\u30ed\u30b0\u30dc\u30c3\u30af\u30b9\u3092\u958b\u304f<\/p>\n<p>If varFileName = False Then<br \/>\nExit Sub<br \/>\nEnd If<\/p>\n<p>&#8216;\u306a\u3093\u3082\u9078\u629e\u3057\u306a\u304b\u3063\u305f\u3068\u304d\u306b\u7d42\u308f\u308b\u7528<\/p>\n<p>intFree = FreeFile<\/p>\n<p>&#8216;\u7a7a\u756a\u53f7\u3092\u53d6\u5f97<\/p>\n<p>Open varFileName For Input As #intFree<\/p>\n<p>&#8216;CSV\u30d5\u30a1\u30a3\u30eb\u3092\u4f7f\u3046\u6e96\u5099<\/p>\n<p>i = 0<br \/>\nDo Until EOF(intFree)<br \/>\nLine Input #intFree, strRec &#8216;1\u884c\u8aad\u307f\u8fbc\u307f<br \/>\ni = i + 1<br \/>\nstrSplit = Split(strRec, &#8220;,&#8221;)<\/p>\n<p>For\u3000 j = 0\u3000 To UBound(strSplit)<br \/>\nCells(i, j + 1) = strSplit(j)<br \/>\nNext<br \/>\n&#8216;\u306a\u3093\u304b\u3044\u308d\u3044\u308d\u3084\u3063\u3066\u30bb\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u5165\u308c\u3066\u304f\u3002<\/p>\n<p>Loop<\/p>\n<p>Close #intFree<\/p>\n<p>&#8216;\u958b\u3044\u3066\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b\u3002<\/p>\n<p>Sheet1.ChartObjects.Add(200, 20, 300, 300).Select<\/p>\n<p>ActiveChart.ChartType = xlXYScatterLinesNoMarkers<br \/>\nActiveChart.SetSourceData Range(Cells(1, 1), Cells(i, j))<\/p>\n<p>\u2019\u30bb\u30eb1,1\u304b\u3089\u30bb\u30ebi,j\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u30b0\u30e9\u30d5\u3092\u4f5c\u308b\u3002<\/p>\n<p>ActiveChart.HasTitle = True<br \/>\nActiveChart.ChartTitle.Text = &#8220;X-Y\u30b0\u30e9\u30d5&#8221;<br \/>\n&#8216;\u30b0\u30e9\u30d5\u306e\u30bf\u30a4\u30c8\u30eb\u3092X-Y\u30b0\u30e9\u30d5\u306b\u3059\u308b\u3002<\/p>\n<p>With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory, \u3000\u3000xlPrimary)<br \/>\n.HasTitle = True<br \/>\n.AxisTitle.Text = &#8220;X&#8221;<\/p>\n<p>End With<\/p>\n<p>&#8216;X\u8ef8\u306e\u8ef8\u540d\u3092X\u306b\u3002<\/p>\n<p>With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue, xlPrimary)<br \/>\n.HasTitle = True<br \/>\n.AxisTitle.Text = &#8220;Y&#8221;<\/p>\n<p>End With<\/p>\n<p>\u2019Y\u8ef8\u306e\u8ef8\u540d\u3092Y\u306b\u3002<\/p>\n<p>End Sub<\/p>\n<p>&#8216;\u7d42\u308f\u308a<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b9f\u884c\u7d50\u679c<\/p>\n<p><a href=\"http:\/\/rgm79sf.asuscomm.com\/wordpress\/?attachment_id=578\" rel=\"attachment wp-att-578\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-578\" src=\"http:\/\/rgm79sf.asuscomm.com\/wordpress\/wp-content\/uploads\/2016\/11\/graph.png\" alt=\"graph\" width=\"796\" height=\"502\" \/><\/a><\/p>\n<p>\u66f8\u3044\u3066\u307f\u308b\u3068\u3042\u3063\u3051\u306a\u3044\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u534a\u65e5\u304f\u3089\u3044\u683c\u95d8\u3057\u3066\u66f8\u304d\u4e0a\u3052\u307e\u3057\u305f\u3002<\/p>\n<p>google\u5148\u751f\u306b\u52a9\u3051\u3089\u308c\u306a\u304c\u3089\u306a\u3093\u3068\u304b\u304b\u3093\u3068\u304b\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3059\u3054\u30fc\u3044\u7c21\u5358\u306a\u30b0\u30e9\u30d5\u3067\u3057\u305f\u304c\u3001\u3053\u308c\u3092\u5fdc\u7528\u3059\u308b\u3053\u3068\u3067CSV\u30d5\u30a1\u30a4\u30eb\u3067\u3042\u308c\u3070\u3044\u308d\u3044\u308d\u5fdc\u7528\u304c\u5229\u304f\u3068\u304b\u5229\u304b\u306a\u3044\u3068\u304b\u3002<\/p>\n<p>\u4f7f\u3044\u3053\u306a\u305b\u308c\u3070\u540c\u3058\u5927\u5b66\u751f\u3067\u3082\u4e00\u6b69\u30ea\u30fc\u30c9\u3067\u304d\u308b\u304b\u30fb\u30fb\u30fb\uff1f<\/p>\n<p>\u307e\u305f\u81ea\u5206\u304c\u601d\u3044\u51fa\u305b\u308b\u3088\u3046\u306b\u30e1\u30e2\u3068\u3057\u3066\u7f6e\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u30b8\u30e0\u3067\u3059\u3002 \u4eca\u65e5\u306e\u6388\u696d\u3067\u3053\u3093\u306a\u8ab2\u984c\u304c\u51fa\u3055\u308c\u307e\u3057\u305f\u3002 Ex&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[24,21,23],"class_list":["post-568","post","type-post","status-publish","format-standard","hentry","category-7","tag-vba","tag-21","tag-23"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts\/568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=568"}],"version-history":[{"count":0,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rgm79sf.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}