Worf

Draw the Ukrainian flag with VBA

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,188
Worf submitted a new Excel article:

Draw the Ukrainian flag with VBA - This article shows six different ways to draw a flag.

The Ukrainian flag is rather easy to draw, and here we will see six distinct ways to do it:

  • 2 user forms without title and borders
  • 2 worksheet cells
  • A Word table
  • A chart
  • 2 shapes
  • 2 text boxes
View attachment 67398
View attachment 67399
VBA Code:
Option Explicit
Rem standard module
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As...

Read more about this Excel article...
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Dan_W

Well-known Member
Joined
Jul 11, 2018
Messages
1,080
Office Version
  1. 365
Platform
  1. Windows
Here's another way:

VBA Code:
Sub DrawFlag()
    Dim Code(1 To 3) As String
    Dim Filename As String: Filename = Environ("TEMP") & "\flag.svg"
    Code(1) = "<svg width=""440"" height=""275"" xmlns=""http://www.w3.org/2000/svg"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xml:space=""preserve"" overflow=""hidden"">"
    Code(2) = "<defs><clipPath id=""clip0""><rect x=""0"" y=""0"" width=""440"" height=""275""/></clipPath></defs>"
    Code(3) = "<g clip-path=""url(#clip0)""><rect x=""0"" y=""0"" width=""440"" height=""138"" fill=""#055AB4""/><rect x=""0"" y=""138"" width=""440"" height=""137"" fill=""#FAD205""/></g></svg>"
    CreateObject("Scripting.FileSystemObject").CreateTextFile(Filename, True).WriteLine Join(Code)
    Application.ActiveSheet.Shapes.AddPicture Filename:=Filename, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=Application.ActiveCell.Left, Top:=Application.ActiveCell.Top, Width:=-1, Height:=-1
    Kill Filename
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,560
Messages
5,854,432
Members
431,648
Latest member
totemos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top