View Single Post
 
Old 10-28-2020, 05:21 PM
Pastor Pastor is offline Windows 10 Office 2019
Novice
 
Join Date: Oct 2020
Posts: 4
Pastor is on a distinguished road
Default

The only way that I could get this to work in ppt is to DECLARE oForm as a VARIANT and NOT as an OBJECT. I am clueless as to why that is. Stupid lucky I guess. But the plot thickens...So I opened a new ppt file and copied the following code into a new module. I clicked on the DESIGNER icon and then clicked on the Public Sub Main() line. Then I clicked on the run macro icon. Userform1 was created successfully and renamed and all of the form properties, including the name, was created perfectly.

So happy to have crossed the finish line I said to myself, "lets see it do that again" so I deleted the form named: CustomMsgBox. I clicked on the reset button, clicked on the DESIGNER icon, clicked on the Public Sub Main() line, then clicked on the run macro icon...and guess what, the Userform1 gets created and the code errors on the line:

.Properties(Name) = "CustomMsgBox"

...if I change "CustomMsgBox" to say, "CustomMsgBox2" the code works! If I migrate to a new file the code will work with the original form name of "CustomMsgBox"! But if I delete the form and rerun the code with the original form name, the code creates UserForm1 but will error on the Name property line with the same error message given in previous posts. The code seems to work with a new unique form name, one that has never been used before in this file, and will NOT allow me to reuse a form name that has been created and subsequently deleted in this file.

Does anyone know of a cure for this mystery? (I know, don't delete the form!)



Option Explicit
Public Sub Main()

p_Rebuild_Form _
sFormName:="CustomMsgBox", _
sCaption:="Message", _
bShowModal:=True, _
bEnabled:=True, _
lBackColor:=vbBlue, _
lForeColor:=vbYellow, _
sTag:="", _
iZoom:=50, _
iTop:=0, _
iLeft:=0, _
iHeight:=200, _
iWidth:=200

End Sub


'************************************************* **********
'* p_REBUILD_FORM *
'************************************************* **********
Public Sub p_Rebuild_Form( _
ByVal sFormName As String, _
ByVal sCaption As String, _
ByVal bShowModal As Boolean, _
ByVal bEnabled As Boolean, _
ByVal lBackColor As Long, _
ByVal lForeColor As Long, _
ByVal sTag As String, _
ByVal iZoom As Integer, _
ByVal iTop As Integer, _
ByVal iLeft As Integer, _
ByVal iHeight As Integer, _
ByVal iWidth As Integer)

'oFORM MUST BE DECLARED AS A VARIANT AND NOT AN OBJECT!
Dim oForm As Variant

'Create a FORM = .Add(3) /3 = FORM's type value
Set oForm = ActivePresentation.VBProject.VBComponents.Add(3)

'Update the FORM Properties
With oForm

'FORM: IDENTIFICATION PROPERTIES
.Properties("Name") = sFormName
.Properties("Caption") = sCaption

'FORM: BEHAVIOR PROPERTIES
.Properties("ShowModal") = bShowModal
.Properties("Enabled") = bEnabled

'FORM: APPEARANCE PROPERTIES
.Properties("BackColor") = lBackColor
.Properties("ForeColor") = lForeColor

'FORM: MISCELLANEOUS PROPERTIES
.Properties("Tag") = sTag
.Properties("Zoom") = iZoom

'FORM: POSITION PROPERTIES
.Properties("StartUpPosition") = 0
.Properties("Top") = iTop
.Properties("Left") = iLeft
.Properties("Height") = iHeight
.Properties("Width") = iWidth

End With

End Sub

Thanks for your time, effort and concern in this matter. God Bless.
Reply With Quote