Search notes:

VBA: Microsoft Forms 2.0 Object Library

Adding a reference to the Forms library

In order to use the Forms library in a VBA project, a reference to the Microsoft Forms 2.0 Object Library must be added, for example by entering one of the following lines in the immediate window:
application.vbe.activeVBProject.references.addFromFile "C:\Windows\System32\FM20.dll"
application.vbe.activeVBProject.references.addFromFile "C:\Windows\SysWOW64\FM20.dll"

application.vbe.activeVBProject.references.addFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0
Note, that this DLL does neither exist under C:\Windows\System32 or C:\Window\SysWOW64, but it is found under C:\Windows\dirs\Program Files (x86)\Microsoft Office\root\vfs\SystemX86\FM20.dll
It is not necessary to manually add the reference if a UserForm is added to a project in the VB Editor. In that case, the Editor will automatically add the required reference.
After adding the reference, constants such as fmBorderStyleSingle or fmBackStyleTransparent become available.

Accessing the clipboard

option explicit

'
'  Needs the "Microsoft Forms 2.0 Object Library" reference.
'  If this reference does not show up, it can be
'  added through the file
'    C:\Windows\System32\FM20.dll  or
'    C:\WINDOWS\SysWOW64\FM20.DLL  respectively
'

sub main()

  dim dObj as new dataObject
  dim txt as string

  txt = "This was copied to the clipboard using VBA!"

  dObj.setText "This text comes from a VBA function!"
  dObj.putInClipboard
  
  msgBox "Text was put in clipboard." & vbCrLf & "Check and put something into the clipboard yourself."
  dObj.getFromClipboard
  
  msgBox "Text currently in clipboard is:" & vbCrLf & dObj.getText

end sub
Github repository about-VBA, path: /object-libraries/microsoft-forms/clipboard.bas
Compare with Putting text into the clipboard with VBA and the WinAPI.

Classes (objects)

CheckBox
ComboBox A ComboBox combines a ListBox and a TextBox: new text can be entered and existing values can be chosen
CommandButton See also this example
Control
Controls
DataObject
Frame
HTMLCheckbox
HTMLHidden
HTMLImage
HTMLOption
HTMLPassword
HTMLReset
HTMLSelect
HTMLSubmit
HTMLText
HTMLTextArea
Image
Label
ListBox Displays a list of values from which a user can choose from. Compare with ComboBox.
MultiPage
NewFont
OptionButton
Page
Pages
PIROWSET
ReturnBoolean
ReturnEffect
ReturnInterger
ReturnSingle
ReturnString
ScrollBar
SpinButton
Tab
Tabs
TabStrip
TextBox Compare with ComboBox. See also this example.
ToggleButton
UserForm See also VBA's global intrinsic variable UserForms.

UserForm

Properties and methods
ActiveControl read-only
BackColor
BorderColor
BorderStyle
CanPaste read-only
CanRedo read-only
CanUndo read-only
Caption
Controls read-only
Copy()
Cut()
Cycle
DesignMode
DrawBuffer
Enabled
Font get, set by ref?
ForeColor
GridX
GridY
InsideHeight read-only
InsideWidth read-only
KeepScrollBarsVisible
MouseIcon
MousePointer
Paste()
Picture
PictureAlignment
PictureSizeMode
PictureTiling
RedoAction()
Repaint()
Scroll()
ScrollBars
ScrollHeight
ScrollLeft
ScrollTop
ScrollWidth
Selected read-only
SetDefaultTabOrder()
ShowGridDots
ShowToolbox
SnapToGrid
SpecialEffect
UndoAction()
VerticalScrollBarSide
Zoom
See also the UserForms collection which stores the loaded UserForm objects.
TODO: There seems to be a different UserForm object with methods such as Show() or Hide()

Dynamically creating a form with VBA

Add references in the immediate window:
thisWorkbook.vbProject.references.addFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3   ' VBIDE
thisWorkbook.vbProject.references.addFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0   ' MS Forms
Paste the following code into a module and execute main in the immediate window:
option explicit

sub main() ' {

    dim proj    as vbIde.vbProject
    dim frmComp as vbide.vbComponent
    dim props   as vbide.properties
    dim frmDsgn as msforms.userForm

    set proj = thisWorkbook.vbProject

    set frmComp = proj.vbComponents.add(vbext_ct_MSForm)
    set frmDsgn = frmComp.designer


    frmComp.name = "dynForm"

    set props = frmComp.properties
    props("caption") = "Dynamic Form"
    props("width"  ) =  500
    props("height" ) =  300

 '     Various attempts to change the font do not wrok:
'   debug.print frmComp.properties("font")
'   debug.print frmComp.properties("designMode")
 '  props("designMode") = 0
 '  debug.print props("font").value
 '  props("font"      ) = "calibri"



    dim i as long
    for i = 1 to frmComp.properties.count
'      debug.print frmComp.properties(i).name
    next i

    frmDsgn.backColor = rgb(255, 222, 111)
  ' frmDsgn.backColor = &h80000005&
  ' frmDsgn.foreColor = &h00404040&

  ' ----------------------------------------------------------
 
    dim okButton as msForms.commandButton

    set okButton = frmDsgn.controls.add("forms.commandButton.1")
    okButton.name      ="ok"
    okButton.caption   ="OK!"

    okButton.top       = 240
    okButton.width     =  60
    okButton.height    =  20
    okButton.left      = 220
    okButton.backColor = rgb(100, 255, 80)
    okButton.font      ="Calibri"

  ' ----------------------------------------------------------
  
    dim frmCode as vbide.codeModule

    set frmCode = frmComp.codeModule

    frmCode.insertLines frmCode.countOfLines + 1, "option explicit"

    frmCode.insertLines frmCode.createEventProc("click", "ok") + 1, "msgBox ""clicked"""
    
  ' ----------------------------------------------------------

    dim appCode as vbIde.codeModule
    set appCode = proj.vbComponents("thisWorkbook").codeModule
    appCode.insertLines appCode.countOfLines + 1, "option explicit"
    appCode.insertLines appCode.countOfLines + 1, "private sub workbook_open()"
    appCode.insertLines appCode.countOfLines + 1, "  " & frmComp.name & ".show"
    appCode.insertLines appCode.countOfLines + 1, "end sub"

end sub ' }

See also

Useful object libraries
The Excel object OLEObject.
Using MS Forms to render HTML text in an Excel cell.
Visual Basic for Applications

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1747715187, '3.20.240.115', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/Useful-object-libraries/Microsoft-Forms/index(288): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78