{"id":337044,"date":"2022-08-15T09:00:45","date_gmt":"2022-08-15T09:00:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337044"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337044","title":{"rendered":"<span>MS Excel \u2014 \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/0c8\/a08\/f98\/0c8a08f98458b19366b469683571cefe.jpg\" width=\"780\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0c8\/a08\/f98\/0c8a08f98458b19366b469683571cefe.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0442\u0438\u043f\u044b \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA MS Excel \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0438\/\u0438\u043b\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438, VBComponent.Type=001, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u0440 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f VBA MS Excel \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c.<\/p>\n<p>\u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e. \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043a\u043e\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u2014 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0438\u0441\u0442\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0432\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043b\u0438\u0441\u0442\u0430.<\/p>\n<pre><code class=\"vbscript\">Private Sub Worksheet_Activate()     ' your code here End Sub  Private Sub Worksheet_Deactivate()     ' your code here End Sub<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u043a\u0443\u0441\u0430 \u0432\u0432\u043e\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u2014 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a, \u043a\u0430\u043a \u0444\u043e\u043a\u0443\u0441 \u0432\u0432\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u043d.<\/p>\n<p>\u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u043b\u0438\u0441\u0442\u0430\u0445 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043d\u0438\u0433 \u0438 \u0444\u043e\u0440\u043c MS Excel.<\/p>\n<p>\u041d\u043e, \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438, Type=001.<\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<ol>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u2014 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 VBA \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA, \u0433\u0434\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 MS EXCEL VBA, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442:<\/p>\n<ol>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c VBA \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 VBA.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c\u0441\u044f \u043e\u0431 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><strong>moduleInit(ByRef Wb As Workbook)<\/strong> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p><strong>moduleLeave(ByRef Wb As Workbook)<\/strong> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 VBA, \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u043b\u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, <strong>Wb<\/strong>, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043d\u0438\u0433\u0443, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"vbscript\">Option Explicit  ' Your VBA module code here  Public Sub moduleInit(ByRef Wb As Workbook)  ' The starting code for your VBA module is here  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u044f\u0434\u043e\u043c:<\/p>\n<pre><code class=\"vbscript\">Option Explicit  ' Your VBA module code here  Public Sub moduleLeave(ByRef Wb As Workbook)  ' The final code for your VBA module is here  End Sub  Public Sub moduleInit(ByRef Wb As Workbook)  ' The starting code for your VBA module is here  End Sub<\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0435\u0442.<\/p>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0438 \u043e\u0434\u043d\u0443 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"vbscript\">Public Const vbaMODULE_INIT As String = \"moduleInit\" Public Const vbaMODULE_LEAVE As String = \"moduleLeave\"  Public Sub vbaWbModuleControl( _ subName As String, _ Optional printDebugOnly As Boolean = False)<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u044e\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440 \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA MS Excel.<\/p>\n<p>\u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"vbscript\">Public Sub moduleInit(ByRef Wb As Workbook)' module initialization Public Sub moduleLeave(ByRef Wb As Workbook)' module completion<\/code><\/pre>\n<p>\u0412 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <strong>vbaWbModuleControl<\/strong> \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430:<\/p>\n<ul>\n<li>\n<p><strong>subName<\/strong> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p><strong>printDebugOnly<\/strong> \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u00ab\u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442\u00bb \u043f\u043e \u0432\u0441\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430 VBA MS Excel, \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <strong>subName<\/strong> \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0438\u0445 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f, \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438.<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a <strong>vbaWbModuleControl<\/strong> \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <strong>printDebugOnly=True<\/strong> \u0432\u044b\u0434\u0430\u0451\u0442 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430, \u043d\u043e \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bc1\/c9c\/c36\/bc1c9cc3630283c636e960cc02441d11.png\" width=\"1025\" height=\"748\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc1\/c9c\/c36\/bc1c9cc3630283c636e960cc02441d11.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u043e\u0442\u0435\u0440\u0438 \u0444\u043e\u043a\u0443\u0441\u0430 \u0432\u0432\u043e\u0434\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 <strong>_Activate()<\/strong>.<\/p>\n<pre><code class=\"vbscript\">Private Sub Workbook_Activate()  vbaWbModuleControl vbaMODULE_INIT  End Sub  Private Sub Workbook_Deactivate()  vbaWbModuleControl vbaMODULE_LEAVE  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043a\u043d\u0438\u0433\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"vbscript\">Private Sub Workbook_Open()   vbaWbModuleControl vbaMODULE_INIT  End Sub  Private Sub Workbook_BeforeClose(Cancel As Boolean)    vbaWbModuleControl vbaMODULE_LEAVE  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<pre><code class=\"vbscript\">Sub ReInitProject()   vbaWbModuleControl vbaMODULE_INIT  End Sub<\/code><\/pre>\n<h2>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/h2>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 [^C;^V] \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 VBA Excel.<\/p>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 MS Excel \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u043a\u0431\u043e\u043a\u0441 \u00ab<em>\u0414\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 VBA<\/em>\u00bb \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab<em>\u0426\u0435\u043d\u0442\u0440 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/em>\u00bb.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5f6\/439\/e2b\/5f6439e2bab0b94cb7e8604ae7214540.png\" width=\"1441\" height=\"971\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5f6\/439\/e2b\/5f6439e2bab0b94cb7e8604ae7214540.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<pre><code class=\"vbscript\">Attribute VB_Name = \"mWbInit\" '*************************************************************************** ' Module \"mWbInit.bas\" ' Controller for automatic initialization of VBA modules ' ' Copyright (c) 2022, \"Nikolay E. Garbuz\" &lt;nik_garbuz@list.ru> ' ' This program is free software: you can redistribute it and\/or modify ' it under the terms of the GNU Lesser General Public License version 3 as ' published by the Free Software Foundation. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ' GNU General Public License for more details. ' ' You should have received a copy of the GNU Lesser General Public License ' along with this program.  If not, see &lt;http:\/\/www.gnu.org\/licenses\/>. ' ' Authored by Nikolay Garbuz &lt;nik_garbuz@list.ru> ' Modified by ' ' TAB Size .EQ 4 '***************************************************************************  Option Explicit Option Compare Text  ' Public Sub moduleInit(ByRef Wb As Workbook) Public Const vbaMODULE_INIT As String = \"moduleInit\"  ' Public Sub moduleLeave(ByRef Wb As Workbook) Public Const vbaMODULE_LEAVE As String = \"moduleLeave\"   ' Call vbaWbModuleControl vbaMODULE_INIT    ' for initialization ' Call vbaWbModuleControl vbaMODULE_LEAVE   ' for release  Public _ Sub vbaWbModuleControl( _                         subName As String, _                         Optional printDebugOnly As Boolean = False _ )     vbaWbModuleRun ThisWorkbook, subName, printDebugOnly End Sub  Public _ Sub vbaWbModuleRun( _                     ByRef Wb As Workbook, _                     subName As String, _                     Optional printDebugOnly As Boolean = False _ )     Dim i As Integer     Dim subList() As String          i = vbaSubroutineList(ThisWorkbook, subName, subList)          If i > 0 Then         If printDebugOnly Then             Debug.Print Join(subList(), vbCrLf)         Else             For i = LBound(subList) To UBound(subList)                 Application.Run subList(i), Wb             Next i         End If     End If          Erase subList End Sub  Private _ Function vbaSubroutineList( _                                 ByRef Wb As Workbook, _                                 sName As String, _                                 ByRef sList() As String _ ) As Integer      Dim i As Long     Dim j As Long     Dim k As Long     Dim l As Long     Dim sc As Long     Dim fc As Long     Dim sLine As String     Dim modName As String     Dim subName As String     Dim chkName As String          ReDim sList(0)          i = InStr(sName, \".\")          If i > 0 Then         modName = Left(sName, i - 1)         subName = Mid(sName, i + 1)     Else         modName = \"\"         subName = sName     End If          sc = vbaModuleIdx(Wb, modName)     If sc > 0 Then         fc = sc     Else         sc = 1         fc = Wb.VBProject.VBComponents.Count     End If          With Wb.VBProject.VBComponents         For i = sc To fc             l = .Item(i).CodeModule.CountOfLines             For j = 1 To l                 chkName = \"\"                 Do                     sLine = .Item(i).CodeModule.Lines(j, 1)                     If Right(sLine, 1) = \"_\" Then                         chkName = chkName &amp; Left(sLine, Len(sLine) - 1)                         j = j + 1                     Else                         chkName = chkName &amp; sLine                         Exit Do                     End If                 Loop                  chkName = vbaRemComment(chkName)                 chkName = vbaRemPrefix(chkName)                 chkName = vbaRemIdentLine(chkName)                 chkName = vbaSubroutineName(chkName)                                  If chkName &lt;> \"\" Then                     If subName = \"*\" Or StrComp(subName, chkName) = 0 Then                         If UBound(sList) &lt; k Then                             ReDim Preserve sList(UBound(sList) + 10)                         End If                                                  sList(k) = .Item(i).Name &amp; \".\" &amp; chkName                         k = k + 1                     End If                 End If             Next j         Next i     End With          If k > 0 Then         ReDim Preserve sList(k - 1)     End If      vbaSubroutineList = k  End Function  Private _ Function vbaModuleIdx( _                                 ByRef Wb As Workbook, _                                 sModuleName As String _ ) As Integer      Dim i As Integer     Dim m As String          vbaModuleIdx = 0          With Wb.VBProject.VBComponents         For i = 1 To .Count             m = .Item(i).Name             If StrComp(sModuleName, m) = 0 Then                 vbaModuleIdx = i                 Exit Function             End If         Next i     End With      End Function  Private _ Function vbaSubroutineName(sLn As String) As String          Const maskSubName As String = \"sub *(*)*\"     Const maskFuncName As String = \"function *(*)*\"          Dim p_space As Integer     Dim p_bra As Integer     Dim sn As String          sn = \"\"          If (sLn Like maskSubName) Or (sLn Like maskFuncName) Then         p_space = InStr(sLn, \" \") + 1         p_bra = InStr(sLn, \"(\")         sn = Mid(sLn, p_space, p_bra - p_space)     End If          vbaSubroutineName = Trim(sn)  End Function  Private _ Function vbaRemComment(sLn As String) As String          Const comSymbols = \"REM ,', REM ,: REM \"         Dim i As Long     Dim s As String     Dim pc As Long          Static csym() As String      On Error GoTo InitArray      i = 0     Do         s = csym(i)                  pc = InStr(sLn, s)                  If pc = 1 Then             sLn = \"\"             Exit Do         Else             If pc > 1 And i > 0 Then                 sLn = Left(sLn, pc - 1)                 Exit Do             End If         End If                  i = i + 1     Loop Until i > UBound(csym)          vbaRemComment = sLn          On Error GoTo 0          Exit Function      InitArray:     csym = Split(comSymbols, \",\")     s = csym(0)     Resume Next      End Function  Private _ Function vbaRemPrefix(sLn As String) As String          Const prefixKeys = \"Public,Private,Friend,Static\"      Dim i As Long     Dim s As String     Dim ps As Long     Dim pf As Long          Static pref() As String          On Error GoTo InitArray          i = 0     Do         s = pref(i)                  ps = InStr(sLn, s)                  If ps > 0 Then             pf = ps + Len(s)             If ps = 1 Then                 sLn = Mid(sLn, pf)             Else                 sLn = Left(sLn, ps - 1) &amp; Mid(sLn, pf)             End If         End If                  i = i + 1     Loop Until i > UBound(pref)          vbaRemPrefix = sLn          On Error GoTo 0          Exit Function      InitArray:     pref = Split(prefixKeys, \",\")     s = pref(0)     Resume Next      End Function  Private _ Function vbaRemIdentLine(sLn As String) As String          Const lnSymbols = \" \" &amp; vbTab &amp; vbCr &amp; vbLf      While sLn &lt;> \"\" And InStr(lnSymbols, Left(sLn, 1)) > 0         sLn = Mid(sLn, 2)     Wend          vbaRemIdentLine = sLn End Function<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/682468\/\"> https:\/\/habr.com\/ru\/post\/682468\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u0442\u0438\u043f\u044b \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA MS Excel \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0438\/\u0438\u043b\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438, VBComponent.Type=001, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u0440 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f VBA MS Excel \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c.<\/p>\n<p>\u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e. \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043a\u043e\u0434\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u2014 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0438\u0441\u0442\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0432\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043b\u0438\u0441\u0442\u0430.<\/p>\n<pre><code class=\"vbscript\">Private Sub Worksheet_Activate()     ' your code here End Sub  Private Sub Worksheet_Deactivate()     ' your code here End Sub<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0444\u043e\u043a\u0443\u0441\u0430 \u0432\u0432\u043e\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u2014 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a, \u043a\u0430\u043a \u0444\u043e\u043a\u0443\u0441 \u0432\u0432\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u043d.<\/p>\n<p>\u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u043b\u0438\u0441\u0442\u0430\u0445 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043d\u0438\u0433 \u0438 \u0444\u043e\u0440\u043c MS Excel.<\/p>\n<p>\u041d\u043e, \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438, Type=001.<\/p>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<ol>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u2014 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 VBA \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA, \u0433\u0434\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<\/li>\n<\/ol>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 MS EXCEL VBA, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442:<\/p>\n<ol>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c VBA \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0442\u043e\u0447\u043d\u044f\u044e\u0449\u0438\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 VBA.<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c\u0441\u044f \u043e\u0431 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><strong>moduleInit(ByRef Wb As Workbook)<\/strong> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p><strong>moduleLeave(ByRef Wb As Workbook)<\/strong> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 VBA, \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u043b\u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, <strong>Wb<\/strong>, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043a\u043d\u0438\u0433\u0443, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"vbscript\">Option Explicit  ' Your VBA module code here  Public Sub moduleInit(ByRef Wb As Workbook)  ' The starting code for your VBA module is here  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0440\u044f\u0434\u043e\u043c:<\/p>\n<pre><code class=\"vbscript\">Option Explicit  ' Your VBA module code here  Public Sub moduleLeave(ByRef Wb As Workbook)  ' The final code for your VBA module is here  End Sub  Public Sub moduleInit(ByRef Wb As Workbook)  ' The starting code for your VBA module is here  End Sub<\/code><\/pre>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0435\u0442.<\/p>\n<h2>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0438 \u043e\u0434\u043d\u0443 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443.<\/p>\n<pre><code class=\"vbscript\">Public Const vbaMODULE_INIT As String = \"moduleInit\" Public Const vbaMODULE_LEAVE As String = \"moduleLeave\"  Public Sub vbaWbModuleControl( _ subName As String, _ Optional printDebugOnly As Boolean = False)<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u044e\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440 \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA MS Excel.<\/p>\n<p>\u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"vbscript\">Public Sub moduleInit(ByRef Wb As Workbook)' module initialization Public Sub moduleLeave(ByRef Wb As Workbook)' module completion<\/code><\/pre>\n<p>\u0412 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <strong>vbaWbModuleControl<\/strong> \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430:<\/p>\n<ul>\n<li>\n<p><strong>subName<\/strong> \u2014 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p><strong>printDebugOnly<\/strong> \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u00ab\u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442\u00bb \u043f\u043e \u0432\u0441\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430 VBA MS Excel, \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <strong>subName<\/strong> \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0438\u0445 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f, \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u043a\u043d\u0438\u0433\u0438.<\/p>\n<p>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 VBA.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a <strong>vbaWbModuleControl<\/strong> \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <strong>printDebugOnly=True<\/strong> \u0432\u044b\u0434\u0430\u0451\u0442 \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430, \u043d\u043e \u0431\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u0430.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u043e\u0442\u0435\u0440\u0438 \u0444\u043e\u043a\u0443\u0441\u0430 \u0432\u0432\u043e\u0434\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 <strong>_Activate()<\/strong>.<\/p>\n<pre><code class=\"vbscript\">Private Sub Workbook_Activate()  vbaWbModuleControl vbaMODULE_INIT  End Sub  Private Sub Workbook_Deactivate()  vbaWbModuleControl vbaMODULE_LEAVE  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043a\u043d\u0438\u0433\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<pre><code class=\"vbscript\">Private Sub Workbook_Open()   vbaWbModuleControl vbaMODULE_INIT  End Sub  Private Sub Workbook_BeforeClose(Cancel As Boolean)    vbaWbModuleControl vbaMODULE_LEAVE  End Sub<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435.<\/p>\n<pre><code class=\"vbscript\">Sub ReInitProject()   vbaWbModuleControl vbaMODULE_INIT  End Sub<\/code><\/pre>\n<h2>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/h2>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 [^C;^V] \u0432 \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 VBA Excel.<\/p>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 MS Excel \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u043a\u0431\u043e\u043a\u0441 \u00ab<em>\u0414\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 VBA<\/em>\u00bb \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab<em>\u0426\u0435\u043d\u0442\u0440 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/em>\u00bb.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<pre><code class=\"vbscript\">Attribute VB_Name = \"mWbInit\" '*************************************************************************** ' Module \"mWbInit.bas\" ' Controller for automatic initialization of VBA modules ' ' Copyright (c) 2022, \"Nikolay E. Garbuz\" &lt;nik_garbuz@list.ru> ' ' This program is free software: you can redistribute it and\/or modify ' it under the terms of the GNU Lesser General Public License version 3 as ' published by the Free Software Foundation. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ' GNU General Public License for more details. ' ' You should have received a copy of the GNU Lesser General Public License ' along with this program.  If not, see &lt;http:\/\/www.gnu.org\/licenses\/>. ' ' Authored by Nikolay Garbuz &lt;nik_garbuz@list.ru> ' Modified by ' ' TAB Size .EQ 4 '***************************************************************************  Option Explicit Option Compare Text  ' Public Sub moduleInit(ByRef Wb As Workbook) Public Const vbaMODULE_INIT As String = \"moduleInit\"  ' Public Sub moduleLeave(ByRef Wb As Workbook) Public Const vbaMODULE_LEAVE As String = \"moduleLeave\"   ' Call vbaWbModuleControl vbaMODULE_INIT    ' for initialization ' Call vbaWbModuleControl vbaMODULE_LEAVE   ' for release  Public _ Sub vbaWbModuleControl( _                         subName As String, _                         Optional printDebugOnly As Boolean = False _ )     vbaWbModuleRun ThisWorkbook, subName, printDebugOnly End Sub  Public _ Sub vbaWbModuleRun( _                     ByRef Wb As Workbook, _                     subName As String, _                     Optional printDebugOnly As Boolean = False _ )     Dim i As Integer     Dim subList() As String          i = vbaSubroutineList(ThisWorkbook, subName, subList)          If i > 0 Then         If printDebugOnly Then             Debug.Print Join(subList(), vbCrLf)         Else             For i = LBound(subList) To UBound(subList)                 Application.Run subList(i), Wb             Next i         End If     End If          Erase subList End Sub  Private _ Function vbaSubroutineList( _                                 ByRef Wb As Workbook, _                                 sName As String, _                                 ByRef sList() As String _ ) As Integer      Dim i As Long     Dim j As Long     Dim k As Long     Dim l As Long     Dim sc As Long     Dim fc As Long     Dim sLine As String     Dim modName As String     Dim subName As String     Dim chkName As String          ReDim sList(0)          i = InStr(sName, \".\")          If i > 0 Then         modName = Left(sName, i - 1)         subName = Mid(sName, i + 1)     Else         modName = \"\"         subName = sName     End If          sc = vbaModuleIdx(Wb, modName)     If sc > 0 Then         fc = sc     Else         sc = 1         fc = Wb.VBProject.VBComponents.Count     End If          With Wb.VBProject.VBComponents         For i = sc To fc             l = .Item(i).CodeModule.CountOfLines             For j = 1 To l                 chkName = \"\"                 Do                     sLine = .Item(i).CodeModule.Lines(j, 1)                     If Right(sLine, 1) = \"_\" Then                         chkName = chkName &amp; Left(sLine, Len(sLine) - 1)                         j = j + 1                     Else                         chkName = chkName &amp; sLine                         Exit Do                     End If                 Loop                  chkName = vbaRemComment(chkName)                 chkName = vbaRemPrefix(chkName)                 chkName = vbaRemIdentLine(chkName)                 chkName = vbaSubroutineName(chkName)                                  If chkName &lt;> \"\" Then                     If subName = \"*\" Or StrComp(subName, chkName) = 0 Then                         If UBound(sList) &lt; k Then                             ReDim Preserve sList(UBound(sList) + 10)                         End If                                                  sList(k) = .Item(i).Name &amp; \".\" &amp; chkName                         k = k + 1                     End If                 End If             Next j         Next i     End With          If k > 0 Then         ReDim Preserve sList(k - 1)     End If      vbaSubroutineList = k  End Function  Private _ Function vbaModuleIdx( _                          <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-337044","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337044"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337044\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}