{"id":578,"date":"2013-03-03T15:53:20","date_gmt":"2013-03-03T15:53:20","guid":{"rendered":"http:\/\/excelvbatutor.com\/?page_id=578"},"modified":"2020-04-23T10:59:18","modified_gmt":"2020-04-23T10:59:18","slug":"excel-vba-lesson-25-animation","status":"publish","type":"page","link":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-25-animation\/","title":{"rendered":"Excel VBA Lesson 25: Creating Animation in Excel VBA"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-24-creating-charts-graphs-excel-vba\/\">&lt;&lt;Lesson 24&gt;&gt;<\/a> <a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\">[Contents]<\/a><\/strong><\/h4>\n\n\n\n<p>Besides creating an Excel VBA&nbsp; code for mathematical and financial calculations, it is also possible to create some fun applications in Excel VBA, including games and animation. Although professionals programmers might not be interested to write such applications, it is worthwhile trying them out as a hobby and for personal satisfaction. Animation can be achieved by changing the position of an object continuously using a looping sub procedure. Two properties or functions that are required to change the positions or coordinates of the object are the Left and Top properties. The Left property specifies the distance of the left edge of the object in pixel from the left border of the screen and the Top property specifies the distance of the top edge of the object from the top border of the screen.<\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br><ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br><script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n\n\n\n<p>For example, the following code makes the object move from left to right then back to left again repeatedly until the user press the stop button. The reset button moves the object back to the starting position.<\/p>\n\n\n\n<p>The code:<\/p>\n\n\n\n<p>Private Sub StartButton_Click()<br>repeat:<\/p>\n\n\n\n<p>With VBAProject.Sheet1.Image1<br>.Left = .Left + 1<br>DoEvents<br>If .Left &gt; 200 Then .Left = 1<br>End With<\/p>\n\n\n\n<p>GoTo repeat<\/p>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg\" alt=\"Excel VBA\"\/><\/figure>\n\n\n\n<p><strong><a href=\"http:\/\/youtu.be\/u97i3qdt4LQ\">&nbsp;<\/a><\/strong><\/p>\n\n\n\n<p>If you wish to move the object up and down, change the above code by replacing the property Left to Top, the code is as follows:<\/p>\n\n\n\n<div class=\"column1\">Private Sub StartButton_Click()<br>repeat:<br>With VBAProject.Sheet1.Image1<br>.Top= .Top+ 1<br>DoEvents<br>If .Top&gt; 200 Then .Top = 1<br>End WithGoTo repeat<\/div>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<p><script async=\"\" src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br><ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9639157585\"><\/ins><br><script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br>If you wish to make the object move diagonally, then use the properties Top and Left at the same time, as follows:<\/p>\n\n\n\n<p>Private Sub StartButton_Click()<br>repeat:<\/p>\n\n\n\n<p>With VBAProject.Sheet1.Image1<\/p>\n\n\n\n<p>.Top = .Top + 5<br>.Left = .Left + 5<\/p>\n\n\n\n<p>DoEvents<br>If .Top &gt; 200 Then .Top = 1<br>If .Left &gt; 200 Then .Left = 1<\/p>\n\n\n\n<p>End With<\/p>\n\n\n\n<p>GoTo repeat<br>End Sub<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><a href=\"http:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-24-creating-charts-graphs-excel-vba\/\">&lt;&lt;Lesson 24&gt;&gt;<\/a>&nbsp;<a href=\"http:\/\/excelvbatutor.com\/index.php\/tutorial\/\">[Contents]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt;Lesson 24&gt;&gt; [Contents] Besides creating an Excel VBA&nbsp; code for mathematical and financial calculations, it is also possible to create some fun applications in Excel VBA, including games and animation. Although professionals programmers might not be interested to write such applications, it is worthwhile trying them out as a hobby and for personal satisfaction. Animation &hellip; <a href=\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-25-animation\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Excel VBA Lesson 25: Creating Animation in Excel VBA&#8221;<\/span><\/a><\/p>\n","protected":false},"author":5012,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-578","page","type-page","status-publish","hentry","category-animation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor<\/title>\n<meta name=\"description\" content=\"This Excel VBA lesson demonstrates how to create animation in Excel VBA\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/excelvbatutor.com\/vba_lesson25.htm\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"og:description\" content=\"This Excel VBA lesson demonstrates how to create animation in Excel VBA\" \/>\n<meta property=\"og:url\" content=\"https:\/\/excelvbatutor.com\/vba_lesson25.htm\" \/>\n<meta property=\"og:site_name\" content=\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-23T10:59:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-25-animation\/\",\"url\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm\",\"name\":\"Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"isPartOf\":{\"@id\":\"https:\/\/excelvbatutor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage\"},\"image\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage\"},\"thumbnailUrl\":\"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg\",\"datePublished\":\"2013-03-03T15:53:20+00:00\",\"dateModified\":\"2020-04-23T10:59:18+00:00\",\"description\":\"This Excel VBA lesson demonstrates how to create animation in Excel VBA\",\"breadcrumb\":{\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/excelvbatutor.com\/vba_lesson25.htm\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage\",\"url\":\"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg\",\"contentUrl\":\"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/excelvbatutor.com\/vba_lesson25.htm#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/excelvbatutor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel VBA Lesson 25: Creating Animation in Excel VBA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/excelvbatutor.com\/#website\",\"url\":\"https:\/\/excelvbatutor.com\/\",\"name\":\"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor\",\"description\":\"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"This Excel VBA lesson demonstrates how to create animation in Excel VBA","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/excelvbatutor.com\/vba_lesson25.htm","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","og_description":"This Excel VBA lesson demonstrates how to create animation in Excel VBA","og_url":"https:\/\/excelvbatutor.com\/vba_lesson25.htm","og_site_name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","article_modified_time":"2020-04-23T10:59:18+00:00","og_image":[{"url":"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/excelvbatutor.com\/index.php\/excel-vba-lesson-25-animation\/","url":"https:\/\/excelvbatutor.com\/vba_lesson25.htm","name":"Excel VBA Lesson 25: Creating Animation in Excel VBA - Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","isPartOf":{"@id":"https:\/\/excelvbatutor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage"},"image":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage"},"thumbnailUrl":"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg","datePublished":"2013-03-03T15:53:20+00:00","dateModified":"2020-04-23T10:59:18+00:00","description":"This Excel VBA lesson demonstrates how to create animation in Excel VBA","breadcrumb":{"@id":"https:\/\/excelvbatutor.com\/vba_lesson25.htm#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/excelvbatutor.com\/vba_lesson25.htm"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/excelvbatutor.com\/vba_lesson25.htm#primaryimage","url":"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg","contentUrl":"https:\/\/excelvbatutor.com\/vba_img\/moveleft.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/excelvbatutor.com\/vba_lesson25.htm#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/excelvbatutor.com\/"},{"@type":"ListItem","position":2,"name":"Excel VBA Lesson 25: Creating Animation in Excel VBA"}]},{"@type":"WebSite","@id":"https:\/\/excelvbatutor.com\/#website","url":"https:\/\/excelvbatutor.com\/","name":"Learn Excel VBA Online \u2013 Step-by-Step Tutorials &amp; Courses | ExcelVBATutor","description":"Master Excel VBA with free tutorials, examples, and personalized guidance. Perfect for beginners and advanced users looking to automate Excel.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/users\/5012"}],"replies":[{"embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/comments?post=578"}],"version-history":[{"count":21,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/578\/revisions"}],"predecessor-version":[{"id":3469,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/pages\/578\/revisions\/3469"}],"wp:attachment":[{"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/media?parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/categories?post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelvbatutor.com\/index.php\/wp-json\/wp\/v2\/tags?post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}