{"id":610,"date":"2025-03-26T00:33:35","date_gmt":"2025-03-25T15:33:35","guid":{"rendered":"https:\/\/hajidai.com\/excel\/2025\/03\/excel-vba%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93%ef%bc%9a%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e6%a5%ad%e5%8b%99%e5%8a%b9\/"},"modified":"2025-03-26T00:33:35","modified_gmt":"2025-03-25T15:33:35","slug":"excel-vba%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93%ef%bc%9a%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e6%a5%ad%e5%8b%99%e5%8a%b9","status":"publish","type":"post","link":"https:\/\/hajidai.com\/excel\/2025\/03\/excel-vba%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93%ef%bc%9a%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e6%a5%ad%e5%8b%99%e5%8a%b9\/","title":{"rendered":"Excel VBA\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\uff1a\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u696d\u52d9\u52b9\u7387\u3092\u5287\u7684\u306b\u5411\u4e0a\u3055\u305b\u308b3\u3064\u306e\u4e0a\u7d1a\u30c6\u30af\u30cb\u30c3\u30af"},"content":{"rendered":"<h2>Excel\u4e0a\u7d1a\u8005\u304c\u7fd2\u5f97\u3059\u3079\u304d\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u624b\u6cd5<\/h2>\n<h3>\u4e0a\u7d1a\u8005\u5411\u3051\u306e\u5373\u52b9\u6027\u306e\u3042\u308b\u30de\u30af\u30ed\u30b3\u30fc\u30c9<\/h3>\n<p>\u4ee5\u4e0b\u306f\u3001\u8907\u6570\u306e\u30b7\u30fc\u30c8\u306e\u30c7\u30fc\u30bf\u30921\u3064\u306e\u30b7\u30fc\u30c8\u306b\u307e\u3068\u3081\u308b\u4fbf\u5229\u306a\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>&#8220;`vba<br \/>\nSub CombineSheets()<br \/>\n    Dim ws As Worksheet<br \/>\n    Dim destSheet As Worksheet<br \/>\n    Dim lastRow As Long<br \/>\n    Dim copyRange As Range<\/p>\n<p>    &#8216; \u7d50\u5408\u5148\u306e\u30b7\u30fc\u30c8\u3092\u4f5c\u6210<br \/>\n    Set destSheet = ThisWorkbook.Sheets.Add<br \/>\n    destSheet.Name = &#8220;Combined Data&#8221;<\/p>\n<p>    &#8216; \u5404\u30b7\u30fc\u30c8\u306e\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30fc<br \/>\n    For Each ws In ThisWorkbook.Sheets<br \/>\n        If ws.Name <> destSheet.Name Then<br \/>\n            lastRow = ws.Cells(ws.Rows.Count, &#8220;A&#8221;).End(xlUp).Row<br \/>\n            Set copyRange = ws.Range(&#8220;A1:C&#8221; &#038; lastRow)<br \/>\n            copyRange.Copy destSheet.Cells(destSheet.Rows.Count, &#8220;A&#8221;).End(xlUp).Offset(1, 0)<br \/>\n        End If<br \/>\n    Next ws<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u30de\u30af\u30ed\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u5185\u306e\u5168\u30b7\u30fc\u30c8\u306eA\u5217\u304b\u3089C\u5217\u306e\u30c7\u30fc\u30bf\u304c\u65b0\u3057\u3044\u30b7\u30fc\u30c8\u306b\u307e\u3068\u3081\u3089\u308c\u307e\u3059\u3002<\/p>\n<h3>1. \u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u672c\u6982\u5ff5<\/h3>\n<p>\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3068\u306f\u3001\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u6280\u8853\u3067\u3059\u3002Excel VBA\u306b\u304a\u3044\u3066\u306f\u3001\u52d5\u7684\u306b\u30de\u30af\u30ed\u3092\u751f\u6210\u3057\u305f\u308a\u3001\u65e2\u5b58\u306e\u30de\u30af\u30ed\u3092\u5206\u6790\u30fb\u4fee\u6b63\u3057\u305f\u308a\u3059\u308b\u624b\u6cd5\u3092\u6307\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u5165\u529b\u306b\u57fa\u3065\u3044\u3066\u81ea\u52d5\u7684\u306b\u30de\u30af\u30ed\u3092\u751f\u6210\u3059\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u983b\u7e41\u306b\u5909\u66f4\u304c\u5fc5\u8981\u306a\u51e6\u7406\u3092\u67d4\u8edf\u306b\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>2. \u52d5\u7684\u306a\u30de\u30af\u30ed\u751f\u6210\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n<p>\u52d5\u7684\u30de\u30af\u30ed\u751f\u6210\u306e\u4e00\u4f8b\u3068\u3057\u3066\u3001\u6587\u5b57\u5217\u3092\u4f7f\u3063\u3066VBA\u30b3\u30fc\u30c9\u3092\u7d44\u307f\u7acb\u3066\u3001\u305d\u308c\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\uff1a<\/p>\n<p>&#8220;`vba<br \/>\nSub CreateDynamicMacro()<br \/>\n    Dim code As String<br \/>\n    code = &#8220;Sub DynamicMacro()&#8221; &#038; vbNewLine &#038; _<br \/>\n           &#8221;    MsgBox &#8220;&#8221;This is a dynamic macro!&#8221;&#8221;&#8221; &#038; vbNewLine &#038; _<br \/>\n           &#8220;End Sub&#8221;<\/p>\n<p>    ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_StdModule).CodeModule.AddFromString code<br \/>\n    Application.Run &#8220;DynamicMacro&#8221;<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u65b0\u3057\u3044\u30de\u30af\u30ed\u3092\u52d5\u7684\u306b\u4f5c\u6210\u3057\u3001\u5373\u5ea7\u306b\u5b9f\u884c\u3057\u307e\u3059\u3002\u30e6\u30fc\u30b6\u30fc\u306e\u5165\u529b\u3084\u7279\u5b9a\u306e\u6761\u4ef6\u306b\u57fa\u3065\u3044\u3066\u3001\u5fc5\u8981\u306a\u30de\u30af\u30ed\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n<h3>3. \u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u30b3\u30fc\u30c9\u5206\u6790<\/h3>\n<p>\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\uff08\u6ce8\uff1a\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u81ea\u5206\u81ea\u8eab\u306e\u69cb\u9020\u3092\u5206\u6790\u3059\u308b\u6280\u8853\uff09\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u65e2\u5b58\u306e\u30de\u30af\u30ed\u306e\u69cb\u9020\u3092\u5206\u6790\u3057\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u4fee\u6b63\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306f\u7279\u306b\u5927\u898f\u6a21\u306aExcel\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u6709\u7528\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u7279\u5b9a\u306e\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u542b\u3080\u3059\u3079\u3066\u306e\u30de\u30af\u30ed\u3092\u898b\u3064\u3051\u51fa\u3057\u3001\u305d\u308c\u3089\u3092\u4e00\u62ec\u3067\u4fee\u6b63\u3059\u308b\u30c4\u30fc\u30eb\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\uff1a<\/p>\n<p>&#8220;`vba<br \/>\nSub AnalyzeAndModifyMacros()<br \/>\n    Dim vbc As VBComponent<br \/>\n    Dim codeMod As CodeModule<br \/>\n    Dim lineNum As Long<br \/>\n    Dim lineContent As String<\/p>\n<p>    For Each vbc In ThisWorkbook.VBProject.VBComponents<br \/>\n        Set codeMod = vbc.CodeModule<br \/>\n        For lineNum = 1 To codeMod.CountOfLines<br \/>\n            lineContent = codeMod.Lines(lineNum, 1)<br \/>\n            If InStr(1, lineContent, &#8220;OldFunction&#8221;) > 0 Then<br \/>\n                codeMod.ReplaceLine lineNum, Replace(lineContent, &#8220;OldFunction&#8221;, &#8220;NewFunction&#8221;)<br \/>\n            End If<br \/>\n        Next lineNum<br \/>\n    Next vbc<br \/>\nEnd Sub<br \/>\n&#8220;`<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u5185\u306e\u3059\u3079\u3066\u306e\u30de\u30af\u30ed\u3092\u691c\u7d22\u3057\u3001&#8221;OldFunction&#8221;\u3068\u3044\u3046\u6587\u5b57\u5217\u3092&#8221;NewFunction&#8221;\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<p>Excel \u30de\u30af\u30ed\u3092\u4f7f\u3063\u305f\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306f\u3001\u5927\u898f\u6a21\u3067\u8907\u96d1\u306aExcel\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7ba1\u7406\u3092\u5927\u5e45\u306b\u52b9\u7387\u5316\u3057\u307e\u3059\u3002\u52d5\u7684\u306a\u30b3\u30fc\u30c9\u751f\u6210\u3001\u81ea\u52d5\u5316\u3055\u308c\u305f\u30b3\u30fc\u30c9\u5206\u6790\u3068\u4fee\u6b63\u3001\u305d\u3057\u3066\u67d4\u8edf\u306a\u30de\u30af\u30ed\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u306b\u3088\u308a\u3001Excel\u306e\u53ef\u80fd\u6027\u3092\u5927\u304d\u304f\u5e83\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3089\u306e\u6280\u8853\u3092\u7fd2\u5f97\u3059\u308b\u3053\u3068\u3067\u3001Excel\u4e0a\u7d1a\u8005\u306f\u3088\u308a\u5f37\u529b\u3067\u52b9\u7387\u7684\u306a\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u696d\u52d9\u30d7\u30ed\u30bb\u30b9\u306e\u6700\u9069\u5316\u306b\u5927\u304d\u304f\u8ca2\u732e\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Excel\u4e0a\u7d1a\u8005\u304c\u7fd2\u5f97\u3059\u3079\u304d\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u624b\u6cd5 \u4e0a\u7d1a\u8005\u5411\u3051\u306e\u5373\u52b9\u6027\u306e\u3042\u308b\u30de\u30af\u30ed\u30b3\u30fc\u30c9 \u4ee5\u4e0b\u306f\u3001\u8907\u6570\u306e\u30b7\u30fc\u30c8\u306e\u30c7\u30fc\u30bf\u30921\u3064\u306e\u30b7\u30fc\u30c8\u306b\u307e\u3068\u3081\u308b\u4fbf\u5229\u306a\u30de\u30af\u30ed\u30b3\u30fc\u30c9\u3067\u3059\u3002 #8220;`vba Sub CombineShe<\/p>\n","protected":false},"author":2,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced"],"_links":{"self":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/comments?post=610"}],"version-history":[{"count":0,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/posts\/610\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/media?parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/categories?post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hajidai.com\/excel\/wp-json\/wp\/v2\/tags?post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}