🇯🇵日本語の説明はこちら
This program converts userforms created in Microsoft Excel VBA into Python Tkinter code.
- 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
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.
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).
- Download the latest file from here and extract it. Use the VBAForm2Tkinter.bas file inside.
- In Excel, go to Developer -> Visual Basic to open VBE.
- Right-click your project and import the provided .bas file using Import File.
- 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.
- If conversion succeeds, a message will appear, and an output.py file will be created in the same directory as your Excel workbook.
- After checking the GUI appearance, edit the .py file and, above .mainloop(), configure event handlers for controls (e.g., button.configure(command=...)).
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.
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.