Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2020, 05:21 PM
Pastor Pastor is offline PPT Macro wont change userform name Windows 10 PPT Macro wont change userform name Office 2019
Novice
PPT Macro wont change userform name
 
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
PPT Macro wont change userform name Change Userform Icon in Taskbar derajlance Word VBA 7 06-01-2019 08:02 PM
Change focus from userForm back to word document to see results. Hank Smith Word VBA 1 08-11-2014 05:00 AM
Change parent for control from frame to userForm? Cosmo Word VBA 0 05-30-2014 02:19 PM
PPT Macro wont change userform name proofing language wont change BigOldArt Word 2 01-18-2013 01:22 PM
[Word 2003] Macro's and a UserForm xanuex Word VBA 0 10-19-2009 05:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft