Skip to content

GUI-Conversion-Tools/VBAForm2Tkinter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VBAForm2Tkinter - Excel VBA UserForm to Tkinter Converter

🇯🇵日本語の説明はこちら

This program converts userforms created in Microsoft Excel VBA into Python Tkinter code.

Example

Image
Image

Converted Elements

  • Variable names (object names)
  • Approximate layout and size of controls
  • Control colors (foreground, background)
  • Text display (Label, CommandButton, CheckBox, OptionButton, MultiPage)
  • Font (typeface, size, bold, italic)
  • Borders (UserForm, Frame, TextBox, Label, ListBox)
  • Mouse cursor
  • Text alignment: left, center, right (Label, TextBox [single line only], ComboBox, CheckBox, OptionButton)
  • Default values of TextBox, ComboBox
  • Items set in ComboBox, ListBox
  • Selection state of OptionButton, CheckBox

Supported Controls

VBA Form Class Tkinter Class
Label tk.Label
CommandButton tk.Button
Frame tk.Frame
TextBox tk.Entry (single line) / tk.Text (multi-line)
Conversion depends on the MultiLine property value (True/False)
SpinButton tk.Spinbox
ListBox tk.Listbox
CheckBox tk.Checkbutton
OptionButton tk.Radiobutton
ScrollBar ttk.Scale
ComboBox ttk.Combobox
MultiPage ttk.Notebook

Note: Captions set on Frame are not reflected. SpinButton behaves differently in VBA and Tkinter, so appearance may vary depending on placement. ScrollBar in VBA has up/down adjustment buttons, but Tkinter’s Scale does not. If unsupported controls exist on the form, the conversion will fail. Please remove those controls and run the conversion again.

Usage

Before using, prepare the Excel workbook containing the user form you want to convert. Also, ensure that the Immediate Window is visible in the VBE (Visual Basic Editor).

Image

  1. Download the latest file from here and extract it. Use the VBAForm2Tkinter.bas file inside.
  2. In Excel, go to Developer -> Visual Basic to open VBE.
  3. Right-click your project and import the provided .bas file using Import File.
  4. In the Immediate Window, enter: Call ConvertForm2Tkinter(UserForm1)
Call ConvertForm2Tkinter(UserForm1)

Note: Replace UserForm1 with the object name of the form you want to convert.

  1. If conversion succeeds, a message will appear, and an output.py file will be created in the same directory as your Excel workbook.
  2. After checking the GUI appearance, edit the .py file and, above .mainloop(), configure event handlers for controls (e.g., button.configure(command=...)).

Control Order (for Controls Without Child Elements)

In Tkinter, if you place one Label on top of another, the later widget appears in front. However, in VBA, you can change front/back order, so the behavior differs. The program first sorts controls by hierarchy level; however, it preserves the original creation order within the same hierarchy. Since VBA’s z-order (front/back) cannot currently be retrieved, some displays may not match VBA.

To adjust:
    Edit the Python code so the widget you want in front is placed later, or Reorder the controls in VBA before conversion.
    For new GUIs, instead of overlapping controls, it is recommended to use containers like Frame, which allow clear parent-child relationships.

Notes on Usage

When using this program in a multi-monitor environment, please temporarily switch to a single monitor or ensure that all monitors have the same scaling percentage. If monitors with different scaling percentages are mixed, the window size may not be calculated correctly.

About

Excel VBA UserForm to Tkinter Converter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages