{"id":4031,"date":"2023-06-28T12:00:26","date_gmt":"2023-06-28T03:00:26","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=4031"},"modified":"2025-11-19T11:12:48","modified_gmt":"2025-11-19T02:12:48","slug":"vba-with","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/vba-with","title":{"rendered":"VBA\u306eWith\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068\u306f\uff1f\u69cb\u6587\u3084\u4f7f\u7528\u4f8b\u3001\u6ce8\u610f\u70b9\u3092\u89e3\u8aac"},"content":{"rendered":"<p>VBA\u3092\u4f5c\u6210\u3059\u308b\u6642\u306b\u3001\u540c\u3058\u3082\u306e\uff08\u30bb\u30eb\u3084\u30b7\u30fc\u30c8\u7b49\uff09\u306b\u5bfe\u3057\u3066\u8907\u6570\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<span>With<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001<strong>\u8907\u6570\u306e\u8a2d\u5b9a\u3092\u7c21\u5358\u306b\u898b\u3084\u3059\u304f\u4f5c\u6210<\/strong>\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u305d\u306e\u8aac\u660e\u3092\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#VBAwith\">\uff11\uff0eVBA\u306ewith\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306b\u3064\u3044\u3066<\/a><ul><li><a href=\"#-with\">\uff11-\uff11\uff0ewith\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068\u306f<\/a><\/li><li><a href=\"#-with-2\">\uff11-\uff12\uff0ewith\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u69cb\u6587<\/a><\/li><\/ul><\/li><li><a href=\"#VBA_with\">\uff12\uff0eVBA with\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4f7f\u7528\u4f8b<\/a><ul><li><a href=\"#i\">\uff12-\uff11\uff0e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u4f8b<\/a><\/li><li><a href=\"#i-2\">\uff12-\uff12\uff0e\u305d\u306e\u4ed6\u306e\u4f7f\u7528\u4f8b<\/a><\/li><\/ul><\/li><li><a href=\"#VBA_with-2\">\uff13\uff0eVBA with\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u969b\u306e\u6ce8\u610f\u70b9<\/a><\/li><li><a href=\"#i-3\">\uff14\uff0e\u6700\u5f8c\u306b<\/a><\/li><\/ul><\/div>\n<h2><span id=\"VBAwith\"><span>\uff11\uff0eVBA\u306ewith<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306b\u3064\u3044\u3066<\/span><\/h2>\n<h3><span id=\"-with\"><span>\uff11-\uff11\uff0ewith<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068\u306f<\/span><\/h3>\n<p><span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068\u306f\u3001\u300c\u5358\u4e00\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u307e\u305f\u306f\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u578b\u306b\u5bfe\u3057\u3066\u4e00\u9023\u306e\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002\u300d\u3068\u66f8\u3044\u3066\u3082\u308f\u304b\u308a\u306b\u304f\u3044\u3068\u601d\u3046\u306e\u3067\u3001\u5c11\u3057\u5177\u4f53\u7684\u306b\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u30bb\u30eb\u306e\u8a2d\u5b9a\u3092\u8aac\u660e\u3092\u3059\u308b\u5834\u5408\u3001\u4f8b\uff11\u306e\u8aac\u660e\u3067\u306f\u300c\u3053\u306e\u30bb\u30eb\u306f\u3001\u300d\u304c\u8a2d\u5b9a\u6bce\u306b\u767b\u5834\u3057\u3066\u3057\u3064\u3053\u304f\u306a\u308a\u307e\u3059\u3002\u4f8b\uff12\u306e\u3088\u3046\u306b\u8aac\u660e\u3059\u308b\u3068\u3001\u3059\u3063\u304d\u308a\u3057\u307e\u3059\u3002<span>With<\/span>\u300c\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306f\u3001\u4f8b\uff12\u306e\u3088\u3046\u306b\u307e\u3068\u3081\u308b\u6642\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<div class=\"attention a-3\">\n<p class=\"attention-title\">\u4f8b\uff11<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u30d5\u30a9\u30f3\u30c8\u540d\u304c\u300c\uff2d\uff33\u3000\uff30\u660e\u671d\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u30b9\u30bf\u30a4\u30eb\u304c\u300c\u592a\u5b57\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u30b5\u30a4\u30ba\u304c\u300c<span>14<\/span>\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u4e0b\u7dda\u8a2d\u5b9a\u304c\u300c\u4e0b\u7dda\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u8272\u304c\u300c\u8d64\u300d\u3067\u3059\u3002<\/p>\n<\/div>\n<div class=\"attention a-3\">\n<p class=\"attention-title\">\u4f8b\uff12<\/p>\n<p>\u3000\u3053\u306e\u30bb\u30eb\u306f\u3001\u6b21\u306e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<p>\u3000\u3000\u30d5\u30a9\u30f3\u30c8\u540d\u304c\u300c\uff2d\uff33\u3000\uff30\u660e\u671d\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3000\u30b9\u30bf\u30a4\u30eb\u304c\u300c\u592a\u5b57\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3000\u30b5\u30a4\u30ba\u304c\u300c<span>14<\/span>\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3000\u4e0b\u7dda\u8a2d\u5b9a\u304c\u300c\u4e0b\u7dda\u300d\u3067\u3059\u3002<\/p>\n<p>\u3000\u3000\u8272\u304c\u300c\u8d64\u300d\u3067\u3059\u3002<\/p>\n<\/div>\n<h3><span id=\"-with-2\">\uff11-\uff12\uff0e<span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u69cb\u6587<\/span><\/h3>\n<p><span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">With object\r\n\u3000\u3000\u3000statement\r\nEnd With\r\n<\/pre>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 18.0514%;\">\u9805\u76ee\u540d<\/td>\n<td style=\"width: 25.173%;\">\u5fc5\u9808\uff0f\u7701\u7565\u53ef\u80fd<\/td>\n<td style=\"width: 56.7755%;\">\u8aac\u660e<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 18.0514%;\">object<\/td>\n<td style=\"width: 25.173%;\">\u5fc5\u9808<\/td>\n<td style=\"width: 56.7755%;\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u307e\u305f\u306f\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u578b\u306e\u540d\u524d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 18.0514%;\">statement<\/td>\n<td style=\"width: 25.173%;\">\u7701\u7565\u53ef\u80fd<\/td>\n<td style=\"width: 56.7755%;\">object\u306b\u5bfe\u3057\u3066\u5b9f\u884c\u3059\u308b<span>1<\/span>\u3064\u4ee5\u4e0a\u306e\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span id=\"VBA_with\">\uff12\uff0eVBA <span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u4f7f\u7528\u4f8b<\/span><\/h2>\n<h3><span id=\"i\">\uff12-\uff11\uff0e\u57fa\u672c\u7684\u306a\u4f7f\u7528\u4f8b<\/span><\/h3>\n<p>\u4e0b\u8a18\u306f\u3001\u9078\u629e\u3057\u3066\u3044\u308b\u30bb\u30eb\u306e\u8a2d\u5b9a\u3092\u5909\u66f4\u3059\u308b\u30bd\u30fc\u30b9\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">sub sample01()\r\n    With Selection.Interior\t\t'\u30bb\u30eb\u306e\u8a2d\u5b9a\r\n        .PatternColorIndex = 3\t'\u30d1\u30bf\u30fc\u30f3\u30f3\u306e\u8272\r\n        .Color = 65535\t\t'\u5857\u308a\u3064\u3076\u3059\u8272\r\n        .TintAndShade = 0\t\t'\u8272\u306e\u660e\u308b\u3055\r\n        .PatternTintAndShade = 0\t'\u8272\u306e\u6fc3\u6de1\r\n    End With\r\nend sub\r\n<\/pre>\n<h3><span id=\"i-2\">\uff12-\uff12\uff0e\u305d\u306e\u4ed6\u306e\u4f7f\u7528\u4f8b<\/span><\/h3>\n<h4><span>\uff12-\uff12-\uff11\uff0e<\/span>\u30cd\u30b9\u30c8\u3092\u4f7f\u3063\u305f\u4f8b<\/h4>\n<p><span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3067\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30cd\u30b9\u30c8\uff08\u5165\u308c\u5b50\uff09\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub sample05()\r\n    \r\n    With Worksheet(sample1) \t '\u300csample1\u300d\u30b7\u30fc\u30c8\u306b\r\n        Range(\"A1\") = \"sample1\"    '\u30bb\u30ebA1\u306b\u300csample1\u300d\u3092\u8a2d\u5b9a\r\n        Range(\"A2\") = \"aaa\"     \t '\u30bb\u30ebA2\u306b\u300caaa\u300d\u3092\u8a2d\u5b9a\r\n        With Worksheet(sample2)\t\t '\u300csample1\u300d\u30b7\u30fc\u30c8\u306b\r\n            Range(\"A1\") = \"sample2\" \t '\u30bb\u30ebA1\u306b\u300csample2\u300d\u3092\u8a2d\u5b9a\r\n            Range(\"A2\") = \"aaa\"     \t '\u30bb\u30ebA2\u306b\u300caaa\u300d\u3092\u8a2d\u5b9a\r\n        End With\r\n    End With\r\nEnd Sub\r\n<\/pre>\n<h2><span id=\"VBA_with-2\">\uff13\uff0eVBA <span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u969b\u306e\u6ce8\u610f\u70b9<\/span><\/h2>\n<p>\u30cd\u30b9\u30c8\u3092\u4f7f\u3046\u6642\u306b\u306f\u3001\u6ce8\u610f\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<span>With<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u30cd\u30b9\u30c8\u306f\u3001\u968e\u5c64\u304c\u6df1\u3044\u5b9a\u7fa9\u304c\u6709\u52b9\u306b\u306a\u308a\u3001\u300c<span>End with<\/span>\u300d\u3067\u629c\u3051\u308b\u3068\u4e00\u3064\u4e0a\u306e<span>with<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u304c\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u306e\u30bd\u30fc\u30b9\u3067\u306f\u3001\u30bb\u30eb<span>A3<\/span>\u306b\u300c<span>AAA<\/span>\u300d\u3092\u8a2d\u5b9a\u306e\u51e6\u7406\u306f\u3001\u300c<span>sanple2<\/span>\u300d\u30b7\u30fc\u30c8\u3067\u306f\u306a\u304f\u300c<span>sample1<\/span>\u300d\u30b7\u30fc\u30c8\u306b\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002<span>With<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u6709\u52b9\u7bc4\u56f2\u306f\u3001\u300c<span>with<\/span>\u300d\u304b\u3089\u300c<span>End\u00a0 with<\/span>\u300d\u307e\u3067\u306e\u7bc4\u56f2\u3067\u3059\u3002<span>With<\/span>\u3067\u5b9a\u7fa9\u3057\u305f\u300c<span>sample1<\/span>\u300d\u30b7\u30fc\u30c8\u306e\u6709\u52b9\u7bc4\u56f2\u306fWith Worksheet(sample1)\u304b\u30892\u56de\u76ee\u306eEnd With\u307e\u3067\u3001\u300c<span>sample2<\/span>\u300d\u30b7\u30fc\u30c8\u306e\u6709\u52b9\u7bc4\u56f2\u306fWith Worksheet(sample2)\u304b\u30891\u56de\u76ee\u306eEnd With\u307e\u3067\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">Sub sample06()\r\n    \r\n    With Worksheet(sample1) '\u300csample1\u300d\u30b7\u30fc\u30c8\u306b\r\n        Range(\"A1\") = \"sample1\"     '\u30bb\u30ebA1\u306b\u300csample1\u300d\u3092\u8a2d\u5b9a\r\n        Range(\"A2\") = \"aaa\"     '\u30bb\u30ebA2\u306b\u300caaa\u300d\u3092\u8a2d\u5b9a\r\n        With Worksheet(sample2) \r\n            Range(\"A1\") = \"sample2\"  '\u30bb\u30ebA1\u306b\u300csample2\u300d\u3092\u8a2d\u5b9a\r\n            Range(\"A2\") = \"aaa\"      '\u30bb\u30ebA2\u306b\u300caaa\u300d\u3092\u8a2d\u5b9a\r\n        End With\r\n        Range(\"A3\") = \"AAA\"     '\u30bb\u30ebA3\u306b\u300cAAA\u300d\u3092\u8a2d\u5b9a\r\n    End With\r\nEnd Sub\r\n<\/pre>\n<h2><span id=\"i-3\">\uff14\uff0e\u6700\u5f8c\u306b<\/span><\/h2>\n<p><span>With<\/span>\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306f\u3001\u4f5c\u6210\u6642\u306e\u30bd\u30fc\u30b9\u91cf\u3092\u5c11\u306a\u304f\u3059\u308b\u3060\u3051\u3067\u306f\u306a\u304f\u3001\u8aad\u307f\u3084\u3059\u304f\u3059\u308b\u76ee\u7684\u3067\u3082\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u6709\u52b9\u306b\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>VBA\u3092\u4f5c\u6210\u3059\u308b\u6642\u306b\u3001\u540c\u3058\u3082\u306e\uff08\u30bb\u30eb\u3084\u30b7\u30fc\u30c8\u7b49\uff09\u306b\u5bfe\u3057\u3066\u8907\u6570\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1fWith\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u6570\u306e\u8a2d\u5b9a\u3092\u7c21\u5358\u306b\u898b\u3084\u3059\u304f\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u305d\u306e\u8aac\u660e\u3092\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u76ee [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4034,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/4031"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=4031"}],"version-history":[{"count":5,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/4031\/revisions"}],"predecessor-version":[{"id":6134,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/4031\/revisions\/6134"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/4034"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=4031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=4031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}