top of page
Search

[Excel animation] Christmas tree

overview

This time, we will introduce a Christmas animation created using Excel VBA.

 

Snow falls on the cell, the color gradient of the letters "Merry Christmas" slowly changes, and the Christmas tree lights rotate and softly twinkle - the result is a work with a sense of movement.

First, please watch the video 👇



PR

This article was created as part of the 2025 Advent Calendar for the Discord community "Excel-Fun.xls*."

Excel-Fun.xls* 2025 Advent Calendar
Excel-Fun.xls* 2025アドベントカレンダー

This is a fun and informative community for Excel and VBA lovers, so please join us!

↓"Excel-Fun.xls* Participation Link"

Excel-Fun.xls*Participation link
Excel-Fun.xls*参加リンク

Technical explanation (Christmas tree)


This blog will focus on the following technical points:

  1. Excel animation basics

  2. Color change animation of gradient text (Merry Christmas)

  3. Snowing effect mechanism (using existing code)

  4. Christmas tree lighting arrangement

  5. Expressing blinking with lighting "blurring effect"

This article summarizes ideas for using Excel as a "canvas" to create animations, rather than as a "static spreadsheet software."


1. Excel animation basics


First, we will explain the basics of Excel animation using the animation below of a circular shape rotating and moving.


The video has a start button, "Run Animation" and a "Stop" button. When you press the "Run Animation" button, the circular shape starts rotating and when you press the "Stop" button, it stops.


The actual code is explained below:

Basic code for Excel animation
Excelアニメーションの基礎コード

As shown in the diagram above, the animation process is divided into three main steps.


① Shape reference and initial settings

First, get the circle shape you want to move (in this example, the name is "Circle"),

Set parameters such as the center position of rotation, radius, and rotation speed.


The value set here will be used in subsequent coordinate calculations.

This determines "which position will be the center and how much it will move."


② Turn off the stop trigger and start the animation

To control the animation,

We have prepared a stop flag (Boolean) called PriJudgeStop.

  • Animation Start: False

  • If the stop button is pressed: True


This is how animations are controlled to be turned on and off.


By making sure this flag is False at the start,

The Do-Loop loop will continue to run correctly.


③ Animation processing using Do-Loop

The main process is a repeat of the Do-Loop.

Each loop corresponds to one frame.


Within the loop, the following steps are executed in order:



Next, we will explain in detail the animation process inside the Do-Loop.

The contents of the Do-Loop in the basic code for Excel animation
Excelアニメーションの基礎コードのDo-Loopの中身

The processing in the red box in the figure is done in Do ~ Loop

  1. Moving and transforming shapes

  2. Reflection on the screen (DoEvents)

  3. Determining the stop process

It has a simple structure that simply repeats these three steps over and over.


① Moving and transforming shapes

First, at the beginning of the loop, we change the position and shape of the circle shape.

Here, Left, Top, etc. are rewritten based on the coordinate calculation results, and the "movement and transformation for the next frame" is determined. (We won't go into detail about the contents of the coordinate calculation here.)


② Reflection on the screen (DoEvents)

Then, call DoEvents to make the changes visible on the screen.

Animation is not visible when you simply change a value; it is only recognized as "movement" when the value is changed, drawn on the screen, changed again, and so on, repeated at high speed.

In this code, DoEvents is executed twice in succession to improve drawing stability. If the movement is choppy, you can adjust the drawing timing by increasing or decreasing the number of DoEvents.


③ Determining whether to stop the process

Finally, we check to see if the stop button was pressed.

On the stop button side, PriJudgeStop = True is set when it is clicked.

This flag is checked each time within Do ~ Loop, and if PriJudgeStop = True, the loop is exited with Exit Do and the animation process is terminated.

The above three stages,

"Movement/Transformation → Screen Reflection → Stop Judgment"

By repeating the above in a Do Loop, continuous animation is achieved on the Excel sheet.

In this work, "Christmas Tree," we are simply doing something more complex with "① Moving and transforming shapes," but the structure of the Excel animation is the same as the one above.



2. Gradient text color change

The text "Merry Christmas" displayed at the bottom of the screen is set to a gradient (two colors) using Excel's "Text Fill" feature.


First, in the formatting pane on the right,

  • Type: Gradient

  • Branch points: 2 (left color, right color)


This is the same as normal shape formatting, and no VBA is used.

Merry Christmas text color setting
Merry Christmasの文字色の設定

2-1. Rewrite two gradient colors from VBA

During the animation, these two colors are rewritten every frame from VBA.

In the code, for the logo shape

TextFrame2 → TextRange → Font → Fill → GradientStops(1),(2).Color.RGB

This directly updates the RGB values of the "left color" and "right color" of the gradient by going through a slightly more in-depth property.


  • GradientStops(1).Color.RGB ... Left color

  • GradientStops(2).Color.RGB ... Right color


By substituting the colors calculated according to the current frame number K into these two places, the color of the entire logo will slowly change.



2-2. Color calculation is separated into two functions


The actual color calculation is

  • Cal_Logo Color 1

  • Cal_Logo Color 2

The internal structure of both functions is almost the same,


  1. Determine the minimum and maximum ranges for each of R, G, and B.

  2. Use a trigonometric function (Cos) to cycle through the range

  3. Finally, return the result as a single color in RGB (R, G, B) format.


This is the process.


Logo Color Calculator
ロゴ色の計算

Since the number of frames for one cycle (20 in this case) is specified, the color will return to its original color every 20 frames, creating a looping color change.


2-3. The two color cycles are shifted by 1/3

The only difference between Cal_Logo Color 1 and Cal_Logo Color 2 is that the timing of the cycle (wave) is shifted by 1/3 .


  • Left color: Cycle starts at 0

  • Right color: Shift the start of the cycle by 1/3


With this image in mind, the "phase" of the trigonometric function has been slightly changed.

This means:


  • The color on the left side starts to change,

  • A little later, the color on the right follows.


This creates a shift in the colors, creating a more gradational effect , rather than the two colors changing at the same time.


3. Snowing animation


The snow that falls across the screen is based on the Excel animation "Snow Falling" that I created previously.

For details, please refer to the link below.

Excelアニメーション「雪が降る」

4. Christmas tree lighting arrangement

The tree lights are made from a number of small circular shapes.

The idea is,

  1. Creating a virtual "cone" in three-dimensional space

  2. Lights are evenly spaced on the surface of the cone

  3. Project it to 2D coordinates on an Excel sheet

These are the steps.

Although the Excel file shows a flat surface, the 3D coordinates are calculated and converted into the "X axis (left and right)" and "Y axis (height)" to create a three-dimensional illuminated tree .


This calculation uses three-dimensional vectors and rotation matrices, but since it would take too long, I will omit the details this time.



5. Recreate the twinkling of lights with a blur effect

The soft light of the lighting can be achieved by using the Soft Edge effect that can be set for shapes.

This is expressed by gradually changing the "blur size" during the animation.


How to express the twinkling of lights
照明の瞬きの表現方法

In Excel's Shape Formatting, there is an option for each shape called [Format Shape → Blur → Size] . Normally, this function only sets a fixed value, but in this case, the blur size value itself is changed dynamically from VBA .


In animation processing, for each frame

  1. Calculate the “blur amount” depending on the current frame number

  2. Assign the calculated value to the shape's SoftEdge.Radius


In this way, the strength of the blur is slowly adjusted.

The function used is a simple trigonometric function (periodic function), which gives

  • The moment when it looks bright

  • The moment the light softly fades

  • The moment it gets bright again


This creates a natural, breathing change in the light.

By directly animating the amount of blur, even a static circular shape can be made to look like blinking LEDs or magical twinkling lights .


summary

In this animation work,

  • Periodic expressions using trigonometric functions

  • Gradient color change over time

  • 3D to 2D projection calculation

  • Animating shape blur effects


It combines a variety of expressions that can also be achieved in Excel , such as:

Excel VBA can be used not only for business automation but also for creating interactive works and performances like this one.

We will continue to introduce fun creations using VBA and technical mechanisms, so please look forward to them.

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

​タグ一覧

配列処理(44)

階層化フォーム(33)

ファイル操作(23)

シート・セル操作(11)

コード自動生成(10)

ユーザーフォーム(8)

図形操作(7)

GAS(5)

アニメーション(5)

技術解説(4)

副業(4)

考え方(4)

条件付き書式(4)

イミディエイトウィンドウ(3)

Enum(3)

Googleスプレッドシート(3)

ココナラ(3)

クリップボード(3)

介護(3)

イベントプロシージャ(2)

PDF(2)

フリーランス(2)

リスキリング(2)

Excel(2)

Excel小ネタ(2)

数学(2)

Outlook(2)

文字列操作(2)

小説(2)

HTML(2)

JavaScript(2)

日報(2)

カレンダー(2)

パズル(2)

ステータスバー(1)

開発効率化(1)

コード解析(1)

静的変数(1)

OneDrive(1)

バックアップ(1)

可変長引数配列(1)

ブック処理(1)

スクレイピング(1)

スプレッドシート(1)

coconala(1)

リボン登録マクロ(1)

QRコード(1)

実行予約(1)

給与計算(1)

VBA不使用(1)

リボン(1)

超勉強会(1)

六角形(1)

Excel遊び(1)

ボウリング(1)

時計(1)

スピログラフ(1)

図名描写(1)

連想配列(1)

イベント(1)

溶接ロボット(1)

VBA(1)

脱Excel(1)

Discord(1)

ECサイト(1)

CSV(1)

楽天(1)

保育士(1)

シフト表(1)

CDP(1)

楽天市場(1)

経理(1)

javascript(1)

医療(1)

文書作成(1)

LookerStudio(1)

シフト(1)

セキュリティ(1)

発注書(1)

ショートカット(1)

WebAPI(1)

色操作(1)

罫線(1)

スーパー開発ショートカット(1)

ライブラリ処理(1)

開発事例(1)

Softex-Celware

Invoice registration number: T5810983887134

  • Facebook
  • Twitter
  • YouTube

©2023 softex-celware. Powered by Wix.com.

bottom of page