{"id":4962,"date":"2016-01-25T08:55:51","date_gmt":"2016-01-24T23:55:51","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=4962"},"modified":"2016-01-25T08:55:51","modified_gmt":"2016-01-24T23:55:51","slug":"codemodulemethod","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/codemodulemethod\/","title":{"rendered":"\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306e\u30b3\u30fc\u30c9\u3092\u64cd\u4f5c\u3059\u308b\uff08CodeModule \u306e\u30e1\u30bd\u30c3\u30c9\uff09"},"content":{"rendered":"<h2>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n<div class=\"m30-l\">\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306e\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\u3001\u524a\u9664\u3001\u7de8\u96c6\u7b49\u3092\u884c\u3046\u5834\u5408\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1c\u53d6\u5f97\uff1e<\/strong><\/span><br \/>\n    <em>object<\/em>.<strong>CodeModule<\/strong><\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>VBComponent \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<\/div>\n<br \/><br \/>\n<h2>CodeModule \u306e\u4e3b\u306a\u30e1\u30bd\u30c3\u30c9<\/h2>\n<div class=\"m30-l\">\n<br \/>\n<h3>CodeModule.AddFromFile \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u5bfe\u8c61\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08\u30e2\u30b8\u30e5\u30fc\u30eb\uff09\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n    \u3053\u306e\u6642\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306b\u3059\u3067\u306b\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u6700\u3082\u4e0a\u306b\u3042\u308b\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u4e0a\u306b\u633f\u5165\u3055\u308c\u307e\u3059\u3002\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u6700\u5f8c\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>AddFromFile<\/strong> ( <em>filename<\/em> )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>filename&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<em>object<\/em> \u3067\u6307\u5b9a\u3057\u305f<strong>\u30e2\u30b8\u30e5\u30fc\u30eb<\/strong>\u306b\u8ffd\u52a0\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u540d\u524d\uff08\u30d1\u30b9\u542b\u3080\uff09\u3092\u8868\u3059\u6587\u5b57\u5217\u5f0f\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<h3>CodeModule.AddFromString \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u6307\u5b9a\u3057\u305f\u6587\u5b57\u5217\u3092\u5bfe\u8c61\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08\u30e2\u30b8\u30e5\u30fc\u30eb\uff09\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n    \u3053\u306e\u6642\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306b\u3059\u3067\u306b\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u6700\u3082\u4e0a\u306b\u3042\u308b\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306e\u4e0a\u306b\u633f\u5165\u3055\u308c\u307e\u3059\u3002\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u6700\u5f8c\u306b\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>AddFromString<\/strong> ( <em>string<\/em> )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>string&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;<em>object<\/em> \u3067\u6307\u5b9a\u3057\u305f<strong>\u30e2\u30b8\u30e5\u30fc\u30eb<\/strong>\u306b\u8ffd\u52a0\u3059\u308b\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<h3>CodeModule.DeleteLines \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3057\u307e\u3059\u3002<em>startline<\/em> \u306b\u6307\u5b9a\u3057\u305f\u884c\u304b\u3089 <em>count<\/em> \u306b\u6307\u5b9a\u3057\u305f\u884c\u6570\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>DeleteLines<\/strong> ( <em>startline<\/em> [, <em>count<\/em> ] )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>startline&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u524a\u9664\u3059\u308b\u5148\u982d\u884c\u3092\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5024\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>count&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u524a\u9664\u3059\u308b\u884c\u6570\u3092\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3057\u305f\u5834\u5408\u306f\u30011 \u884c\u524a\u9664\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<h3>CodeModule.InsertLines \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u6307\u5b9a\u3057\u305f\u884c\u306b\u3001\u6587\u5b57\u5217\uff08\u30b3\u30fc\u30c9\uff09\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>InsertLines<\/strong> ( <em>startline<\/em>, <em>code<\/em> )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>startline&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u633f\u5165\u3059\u308b\u884c\u3092\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5024\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>code&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u633f\u5165\u3059\u308b\u30b3\u30fc\u30c9\u3092\u6587\u5b57\u5217\u578b\uff08String\uff09\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002\u6587\u5b57\u5217\u306b\u3001\u6539\u884c\u30b3\u30fc\u30c9\uff08\u30ad\u30e3\u30ea\u30c3\u30b8\u30ea\u30bf\u30fc\u30f3\u3001\u30e9\u30a4\u30f3\u30d5\u30a3\u30fc\u30c9\uff09\u3092\u542b\u3093\u3067\u3044\u308b\u5834\u5408\u306f\u3001\u9023\u7d9a\u3057\u305f\u884c\u3068\u3057\u3066\u633f\u5165\u3055\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<h3>CodeModule.ReplaceLine \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u65e2\u5b58\u306e\u6307\u5b9a\u3057\u305f\u884c\u3092\u6307\u5b9a\u3057\u305f\u30b3\u30fc\u30c9\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>ReplaceLine<\/strong>  ( <em>startline<\/em>, <em>code<\/em> )<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h3>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>startline&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u7f6e\u63db\u3059\u308b\u884c\u3092\u9577\u6574\u6570\u578b\uff08Long\uff09\u306e\u5024\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>code&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u7f6e\u63db\u3059\u308b\u30b3\u30fc\u30c9\u3092\u6587\u5b57\u5217\u578b\uff08String\uff09\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<\/div>\n<br \/><br \/>\n<h2>CodeModule \u30e1\u30bd\u30c3\u30c9 \u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">AddFromFile \u30e1\u30bd\u30c3\u30c9 \/ AddFromString \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"CodeModule \u30e1\u30bd\u30c3\u30c9 \u4f7f\u7528\u4f8b 1\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_CodeModule04()\r\n    'AddFromFile \u30e1\u30bd\u30c3\u30c9\r\n    'AddFromString \u30e1\u30bd\u30c3\u30c9\r\n\r\n    Dim FileName As String\r\n    Dim FileCode As String\r\n    Dim w As Workbook\r\n    Dim stdm As Object\r\n    Dim str As String\r\n    \r\n    FileName = \"C:\\Documents\\test01.xlsm\"\r\n    FileCode = \"C:\\Documents\\tmp\\code.txt\"\r\n    \r\n    '\u30d6\u30c3\u30af\uff08test01.xlsm\uff09\u3092\u30aa\u30fc\u30d7\u30f3\r\n    Set w = Workbooks.Open(FileName)\r\n\r\n    With w.VBProject.VBComponents\r\n        \r\n        '\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30eb\uff08Module1\uff09\u306b\u3001code.txt \u306e\u5185\u5bb9\uff08sample_macro01\uff09\u3092\u8ffd\u52a0\r\n        .Item(\"Module1\").CodeModule.AddFromFile (FileCode)\r\n        \r\n        '\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30eb\uff08Module1\uff09\u306b\u3001\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\r\n        .Item(\"Module1\").CodeModule.AddFromString \"public myValue as integer\"\r\n\r\n    End With\r\n    \r\n    '\u8ffd\u52a0\u3057\u305f\u30de\u30af\u30ed\uff08sample_macro01\uff09\u3092\u5b9f\u884c\r\n    Application.Run \"'\" & FileName & \"'\" & \"!sample_macro01\"\r\n    \r\n    \r\n    Application.DisplayAlerts = False\r\n    \r\n    '\u4fdd\u5b58\u3057\u3066\u7d42\u4e86\r\n    w.Save\r\n    w.Close\r\n    Set w = Nothing\r\n    \r\n    Application.DisplayAlerts = True\r\n\r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 1<\/h3>\n<p>\u300cAddFromFile \u30e1\u30bd\u30c3\u30c9 \/ AddFromString \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c\u3059\u308b\u524d\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1.jpg?resize=580%2C318&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 1-1\" width=\"580\" height=\"318\" class=\"alignnone size-large wp-image-4963\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1.jpg?resize=580%2C318&amp;ssl=1 580w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1.jpg?resize=400%2C219&amp;ssl=1 400w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1.jpg?w=641&amp;ssl=1 641w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>code.txt \u306e\u5185\u5bb9\uff08sample_macro01\uff09<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-2.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-2.jpg?resize=537%2C258&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 1-2\" width=\"537\" height=\"258\" class=\"alignnone size-full wp-image-4964\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-2.jpg?w=537&amp;ssl=1 537w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-2.jpg?resize=400%2C192&amp;ssl=1 400w\" sizes=\"(max-width: 537px) 100vw, 537px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cAddFromFile \u30e1\u30bd\u30c3\u30c9 \/ AddFromString \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-3.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-3.jpg?resize=168%2C155&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 1-3\" width=\"168\" height=\"155\" class=\"alignnone size-full wp-image-4966\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cAddFromFile \u30e1\u30bd\u30c3\u30c9 \/ AddFromString \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c\u5f8c\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-4.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-4.jpg?resize=580%2C364&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 1-4\" width=\"580\" height=\"364\" class=\"alignnone size-large wp-image-4967\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-4.jpg?resize=580%2C364&amp;ssl=1 580w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-4.jpg?resize=400%2C251&amp;ssl=1 400w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-4.jpg?w=677&amp;ssl=1 677w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">DeleteLines \u30e1\u30bd\u30c3\u30c9 \/ ProcBodyLine \u30d7\u30ed\u30d1\u30c6\u30a3 \/ ProcCountLines \u30d7\u30ed\u30d1\u30c6\u30a3 \/ Lines \u30d7\u30ed\u30d1\u30c6\u30a3 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"CodeModule \u30e1\u30bd\u30c3\u30c9 \u4f7f\u7528\u4f8b 2\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_CodeModule05()\r\n    \r\n    '\u203b Sample_CodeModule04() \u3092\u5b9f\u884c\u5f8c\u306b\u5b9f\u884c\r\n    \r\n    'DeleteLines \u30e1\u30bd\u30c3\u30c9\r\n    'ProcBodyLine \u30d7\u30ed\u30d1\u30c6\u30a3\r\n    'ProcCountLines \u30d7\u30ed\u30d1\u30c6\u30a3\r\n    'Lines \u30d7\u30ed\u30d1\u30c6\u30a3\r\n\r\n    Dim FileName As String\r\n    Dim FileCode As String\r\n    Dim w As Workbook\r\n    Dim LineS As Integer\r\n    Dim LineE As Integer\r\n    Dim str As String\r\n    \r\n    FileName = \"C:\\Documents\\test01.xlsm\"\r\n    FileCode = \"C:\\Documents\\tmp\\code.txt\"\r\n    \r\n    '\u30d6\u30c3\u30af\uff08test01.xlsm\uff09\u3092\u30aa\u30fc\u30d7\u30f3\r\n    Set w = Workbooks.Open(FileName)\r\n\r\n    With w.VBProject.VBComponents.Item(\"Module1\").CodeModule\r\n    \r\n        'Sample_CodeModule04\u3067\u8ffd\u52a0\u3057\u305f\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\uff08sample_macro01\uff09\u3092\u524a\u9664\r\n            \r\n        'Module1 \u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u300csample_macro01\u300d\u306e\u958b\u59cb\u884c\u3092\u53d6\u5f97\r\n        LineS = .ProcStartLine(\"sample_macro01\", 0)\r\n        \r\n        'Module1 \u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u300csample_macro01\u300d\u306e\u884c\u6570\u3092\u53d6\u5f97\r\n        LineE = .ProcCountLines(\"sample_macro01\", 0)\r\n        \r\n        '\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u300csample_macro01\u300d\u306e\u5185\u5bb9\u3092\u5909\u6570\u306b\u683c\u7d0d\r\n        str = .LineS(LineS, LineE)\r\n        \r\n        'sample_macro01 \u3092\u958b\u653e\uff08\u524a\u9664\uff09\r\n        .DeleteLines LineS, LineE\r\n        \r\n        \r\n        'Sample_CodeModule04\u3067\u8ffd\u52a0\u3057\u305f\u30c6\u30ad\u30b9\u30c8\uff084\u884c\u76ee\u306e\u307f\uff09\u3092\u524a\u9664\r\n        .DeleteLines 4\r\n        \r\n    End With\r\n    \r\n        'sample_macro01\uff08\u524a\u9664\u6e08\uff09\u306e\u5185\u5bb9\u3092\u8868\u793a\r\n        MsgBox str\r\n    \r\n\r\n    Application.DisplayAlerts = False\r\n    \r\n    '\u4fdd\u5b58\u3057\u3066\u7d42\u4e86\r\n    w.Save\r\n    w.Close\r\n    Set w = Nothing\r\n\r\n    Application.DisplayAlerts = True\r\n    \r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 2<\/h3>\n<p>Sample_CodeModule04() \u3092\u5b9f\u884c\u5f8c\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-1.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-1.jpg?resize=580%2C364&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 2-1\" width=\"580\" height=\"364\" class=\"alignnone size-large wp-image-4968\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-1.jpg?resize=580%2C364&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-1.jpg?resize=400%2C251&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-1.jpg?w=677&amp;ssl=1 677w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cDeleteLines \u30e1\u30bd\u30c3\u30c9 \/ ProcBodyLine \u30d7\u30ed\u30d1\u30c6\u30a3 \/ ProcCountLines \u30d7\u30ed\u30d1\u30c6\u30a3 \/ Lines \u30d7\u30ed\u30d1\u30c6\u30a3 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-2.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-2.jpg?resize=202%2C215&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 2-2\" width=\"202\" height=\"215\" class=\"alignnone size-full wp-image-4969\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cDeleteLines \u30e1\u30bd\u30c3\u30c9 \/ ProcBodyLine \u30d7\u30ed\u30d1\u30c6\u30a3 \/ ProcCountLines \u30d7\u30ed\u30d1\u30c6\u30a3 \/ Lines \u30d7\u30ed\u30d1\u30c6\u30a3 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c\u5f8c\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-3.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-3.jpg?resize=580%2C309&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 2-3\" width=\"580\" height=\"309\" class=\"alignnone size-large wp-image-4970\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-3.jpg?resize=580%2C309&amp;ssl=1 580w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-3.jpg?resize=400%2C213&amp;ssl=1 400w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule05-3.jpg?w=690&amp;ssl=1 690w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<br \/><br \/>\n<h3 id=\"vba_sample\">InsertLines \u30e1\u30bd\u30c3\u30c9 \/ ReplaceLine \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"CodeModule \u30e1\u30bd\u30c3\u30c9 \u4f7f\u7528\u4f8b 3\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_CodeModule06()\r\n    \r\n    'InsertLines \u30e1\u30bd\u30c3\u30c9\r\n    'ReplaceLine \u30e1\u30bd\u30c3\u30c9\r\n\r\n    Dim FileName As String\r\n    Dim w As Workbook\r\n    Dim str As String\r\n    \r\n    FileName = \"C:\\Documents\\test02.xlsm\"\r\n\r\n    '\u30d6\u30c3\u30af\uff08test02.xlsm\uff09\u3092\u30aa\u30fc\u30d7\u30f3\r\n    Set w = Workbooks.Open(FileName)\r\n\r\n    With w.VBProject.VBComponents.Item(\"Module1\").CodeModule\r\n                \r\n        '\u6587\u5b57\u5217\u3092\u633f\u5165\r\n        .InsertLines 7, \"    str=\"\"\u304a\u306f\u3088\u3046\u3054\u3056\u3044\u307e\u3059\u3002\"\"\"\r\n        \r\n        '\u6587\u5b57\u5217\u7f6e\u63db\r\n        .ReplaceLine 9, \"    msgbox str\"\r\n        \r\n        'Module1 \u306e\u5185\u5bb9\r\n        str = .LineS(1, .CountOfLines)\r\n        \r\n    End With\r\n    \r\n        'Module1 \u306e\u5185\u5bb9\u3092\u8868\u793a\r\n        MsgBox str\r\n    \r\n    Application.DisplayAlerts = False\r\n    \r\n    '\u4fdd\u5b58\u3057\u3066\u7d42\u4e86\r\n    w.Save\r\n    w.Close\r\n    Set w = Nothing\r\n    \r\n    Application.DisplayAlerts = True\r\n    \r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c 3<\/h3>\n<p>\u300cInsertLines \u30e1\u30bd\u30c3\u30c9 \/ ReplaceLine \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c\u3059\u308b\u524d\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-1.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-1.jpg?resize=454%2C261&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 3-1\" width=\"454\" height=\"261\" class=\"alignnone size-full wp-image-4971\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-1.jpg?w=454&amp;ssl=1 454w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-1.jpg?resize=400%2C230&amp;ssl=1 400w\" sizes=\"(max-width: 454px) 100vw, 454px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cInsertLines \u30e1\u30bd\u30c3\u30c9 \/ ReplaceLine \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-2.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-2.jpg?resize=217%2C305&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 3-2\" width=\"217\" height=\"305\" class=\"alignnone size-full wp-image-4972\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u300cInsertLines \u30e1\u30bd\u30c3\u30c9 \/ ReplaceLine \u30e1\u30bd\u30c3\u30c9 \u3092\u4f7f\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u300d\u3092\u5b9f\u884c\u5f8c\u306e test01.xlsm \u306e Module1 \u306e\u5185\u5bb9<\/p>\n<p><a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-3.jpg?ssl=1\" rel=\"lightbox[4962]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-3.jpg?resize=453%2C205&#038;ssl=1\" alt=\"CodeModule \u30e1\u30bd\u30c3\u30c9 3-3\" width=\"453\" height=\"205\" class=\"alignnone size-full wp-image-4973\" srcset=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-3.jpg?w=453&amp;ssl=1 453w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule06-3.jpg?resize=400%2C181&amp;ssl=1 400w\" sizes=\"(max-width: 453px) 100vw, 453px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>CodeModule \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 \u30e2\u30b8\u30e5\u30fc\u30eb\u5185\u306e\u30b3\u30fc\u30c9\u306e\u8ffd\u52a0\u3001\u524a\u9664\u3001\u7de8\u96c6\u7b49\u3092\u884c &#8230; <\/p>\n","protected":false},"author":1,"featured_media":4995,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[696],"tags":[773,774,765,775,776,777,63,764,698,749,38],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2016\/01\/CodeModule04-1-580x318-1.jpg?fit=580%2C318&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1i2","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4962"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=4962"}],"version-history":[{"count":3,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4962\/revisions"}],"predecessor-version":[{"id":4994,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/4962\/revisions\/4994"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/4995"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=4962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=4962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=4962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}