{"id":1478,"date":"2023-10-20T22:31:29","date_gmt":"2023-10-20T14:31:29","guid":{"rendered":"https:\/\/lyvba.com\/?p=1478"},"modified":"2023-10-20T22:42:04","modified_gmt":"2023-10-20T14:42:04","slug":"zerobasevba101","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/10\/20\/zerobasevba101\/","title":{"rendered":"CorelDRAW VBA\u63d2\u4ef6\u5f00\u53d1 \u4f7f\u7528ShapeRange\u548c\u5b57\u5178"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/10\/VBA.webp\" alt=\"\" \/><\/p>\n<h4><a href=\"https:\/\/b23.tv\/V5TmFOp\">\u3010CorelDRAW VBA\u63d2\u4ef6\u5f00\u53d1 \u4f7f\u7528ShapeRange\u548c\u5b57\u5178-\u54d4\u54e9\u54d4\u54e9\u3011<\/a>  <a href=\"https:\/\/b23.tv\/V5TmFOp\">https:\/\/b23.tv\/V5TmFOp<\/a><\/h4>\n<h2>\u7b80\u4ecb \u8fd9\u6bb5 <em>CorelDRAW VBA<\/em> \u5b66\u4e60\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u529f\u80fd\uff0c\u5373\u5bf9\u6240\u9009\u5f62\u72b6\u8fdb\u884c\u989c\u8272\u7d22\u5f15\u548c\u7edf\u8ba1\u3002<\/h2>\n<pre><code class=\"language-vb\">Sub \u5236\u4f5c\u989c\u8272\u7d22\u5f15()\n  Dim sr As ShapeRange\n  Dim csr As New ShapeRange\n  Dim s As Shape\n  Dim rgb As New Color\n  Set sr = ActiveSelectionRange\n\n  Set dict = CreateObject(&quot;Scripting.dictionary&quot;)\n\n  For Each s In sr\n    rgb.CopyAssign s.Fill.UniformColor\n    rgb.ConvertToRGB\n    &#039;\/\/  Debug.Print rgb.ToString\n\n    &#039;\/\/ \u4f7f\u7528RGB\u989c\u8272\u5efa\u7acb\u5b57\u5178\u548c\u8ba1\u6570\n    If dict.Exists(rgb.ToString) = True Then\n      dict.Item(rgb.ToString) = dict.Item(rgb.ToString) + 1\n    Else\n      dict.Add rgb.ToString, 1\n      csr.Add s\n    End If\n  Next s\n\n  MsgBox &quot;\u989c\u8272\u7edf\u8ba1: &quot; &amp; csr.Count &amp; &quot; \u79cd\u586b\u5145\u989c\u8272&quot; &amp; vbNewLine &amp; &quot;\u7d22\u5f15\u989c\u8272\u7b2c\u4e00\u4e2a\u7269\u4ef6\u5728 csr \u7269\u4ef6\u8303\u56f4\u5185&quot;\n  csr.CreateSelection\n\nEnd Sub\n<\/code><\/pre>\n<h2>\u4e0b\u9762\u6765\u5206\u6bb5\u89e3\u91ca,\u4ee3\u7801\u7684\u4e3b\u8981\u903b\u8f91\u5982\u4e0b\uff1a<\/h2>\n<ul>\n<li>\n<p>\u58f0\u660e\u4e86\u4e00\u4e9b\u53d8\u91cf\uff0c\u5305\u62ecShapeRange\u5bf9\u8c61sr\u548ccsr\uff0cShape\u5bf9\u8c61s\uff0cColor\u5bf9\u8c61rgb\uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b57\u5178\u5bf9\u8c61dict\u3002<\/p>\n<pre><code>Dim sr As ShapeRange\nDim csr As New ShapeRange\nDim s As Shape\nDim rgb As New Color<\/code><\/pre>\n<\/li>\n<li>\n<p>\u901a\u8fc7<code>Set sr = ActiveSelectionRange<\/code>\u83b7\u53d6\u5f53\u524d\u7684\u9009\u4e2d\u5f62\u72b6\u8303\u56f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2aScripting.dictionary\u5bf9\u8c61dict\uff0c\u7528\u4e8e\u5b58\u50a8\u989c\u8272\u548c\u8ba1\u6570\u7684\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u9009\u4e2d\u5f62\u72b6\u8303\u56f4\u4e2d\u7684\u6bcf\u4e2a\u5f62\u72b6s<\/p>\n<\/li>\n<li>\n<p>\u5c06\u5f53\u524d\u5f62\u72b6s\u7684\u586b\u5145\u989c\u8272\u590d\u5236\u7ed9Color\u5bf9\u8c61rgb\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aRGB\u989c\u8272\u7a7a\u95f4\u3002<\/p>\n<pre><code>rgb.CopyAssign s.Fill.UniformColor\nrgb.ConvertToRGB\nDebug.Print rgb.ToString<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>Debug.Print<\/code> \u628a\u8c03\u8bd5\u4fe1\u606f\u6253\u5370\u51fa\u6765\u68c0\u67e5<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528RGB\u989c\u8272\u4f5c\u4e3a\u952e\uff0c\u5728\u5b57\u5178dict\u4e2d\u8fdb\u884c\u67e5\u627e\u3002\u5982\u679c\u5b57\u5178\u4e2d\u5df2\u5b58\u5728\u8be5\u952e\uff0c\u5219\u5c06\u5bf9\u5e94\u7684\u503c\u52a01\uff1b\u5982\u679c\u5b57\u5178\u4e2d\u4e0d\u5b58\u5728\u8be5\u952e\uff0c\u5219\u5c06\u8be5\u952e\u548c\u503c1\u6dfb\u52a0\u5230\u5b57\u5178\u4e2d\uff0c\u5e76\u5c06\u5f53\u524d\u5f62\u72b6s\u6dfb\u52a0\u5230csr\u4e2d\u3002<\/p>\n<pre><code>If dict.Exists(rgb.ToString) = True Then\ndict.Item(rgb.ToString) = dict.Item(rgb.ToString) + 1\nElse\ndict.Add rgb.ToString, 1\ncsr.Add s\nEnd If<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5faa\u73af\u7ed3\u675f\u540e\uff0c\u4f7f\u7528<code>csr.Count<\/code>\u83b7\u53d6csr\u4e2d\u5f62\u72b6\u7684\u6570\u91cf\uff0c\u5f39\u51fa\u4e00\u4e2a\u6d88\u606f\u6846\u663e\u793a\u989c\u8272\u7edf\u8ba1\u7ed3\u679c\uff0c\u5e76\u5c06csr\u4e2d\u7684\u5f62\u72b6\u521b\u5efa\u4e3a\u65b0\u7684\u9009\u4e2d\u8303\u56f4\u3002<br \/>\n<code> csr.CreateSelection <\/code><\/p>\n<\/li>\n<\/ul>\n<h3>\u603b\u7ed3\u6765\u8bf4\uff0c\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u5bf9\u6240\u9009\u5f62\u72b6\u7684\u586b\u5145\u989c\u8272\u8fdb\u884c\u7d22\u5f15\u548c\u7edf\u8ba1\uff0c\u5e76\u5c06\u5177\u6709\u76f8\u540c\u586b\u5145\u989c\u8272\u7684\u5f62\u72b6\u653e\u5165\u4e00\u4e2aShapeRange\u5bf9\u8c61\u4e2d\u3002\u6700\u540e\uff0c\u901a\u8fc7\u6d88\u606f\u6846\u663e\u793a\u7edf\u8ba1\u7ed3\u679c\uff0c\u5e76\u5c06\u8fd9\u4e9b\u5f62\u72b6\u4f5c\u4e3a\u65b0\u7684\u9009\u4e2d\u8303\u56f4\u3002<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u3010CorelDRAW VBA\u63d2\u4ef6\u5f00\u53d1 \u4f7f\u7528ShapeRange\u548c\u5b57\u5178-\u54d4\u54e9\u54d4\u54e9\u3011 https:\/\/b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1479,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[67],"class_list":["post-1478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","tag-vba"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1478"}],"version-history":[{"count":2,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1478\/revisions"}],"predecessor-version":[{"id":1481,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1478\/revisions\/1481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media\/1479"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}