Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2020, 09:19 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
Question PPT Macro wont change userform name

I've entered this macro code into a module in a new ppt vbproject module:



Public Sub Rebuild_Custom_Message_Box()

Dim oForm As Object

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

'Change the Name of the new form
oForm.Name = "CustomMsgBox"

'Change the Caption
oForm.Caption = "Message"

End Sub


See attached Word Document with two screen shots of the error.

I get a runtime error " #75: could not find the specified object" on the line shown in red text.

Userform1 is created and appears in the VBProject pane under the Forms folder Icon.

What is the correct macro code to change the name and caption of a newly created UserForm?


Thanks for your time, effort and concern in this matter.
Reply With Quote
  #2  
Old 10-24-2020, 11:33 PM
JohnWilson JohnWilson is offline PPT Macro wont change userform name Windows 10 PPT Macro wont change userform name Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,825
JohnWilson will become famous soon enoughJohnWilson will become famous soon enough
Default

You might want to say WHY you want to do this.

If it's for your own use it is much easier to create and name manually
If you are trying to send to others it is very unlikely thay will have enabled access to the VBE and it will fail anyway.
__________________
Microsoft PowerPoint MVP
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #3  
Old 10-25-2020, 10:56 AM
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

John,

Thanks for reaching out to me on this issue.

I am trying to build a routine that will contain all of the desired property values so that if and when the code fails I have a way to easily rebuild the form and all of its controls, and properties quickly. In addition, when I want to redesign the forms or tweek them I can more easily delete the old form, change the rebuild code and then run the rebuild code to help insure that the form is rebuilt soundly and has somehow not been compromised or inadvertently corrupted.

( I am not a professional programmer and have found this to be my best strategy for enhancing Excel projects and now, hopefully, Powerpoint presentations, for use in the operation of my two churches.)

In Exel I have accomplished this rebuild strategy and it has worked reliably for years, but when I began to export and import the code modules to Powerpoint and taylor them to the ppt code modules I began to run into "incompatibility?" problems.

I have posed this problem in the context of a new ppt file and with no other code to try and isolate the problem and to make sure that there is no other code that could somehow interfere with this code.

Do I need to be in some other "mode" or "environment" like some sort of "design" environment for this to work properly?
Reply With Quote
  #4  
Old 10-25-2020, 11:11 AM
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

John,

Here is the code that works in EXEC that I mentioned in my previous response that has worked for years. With my best attempts to modify the code as little as possible to get it to work in the ppt code module file It failed at the renaming of the newly created user form.

'************************************************* **********
'* PUT THIS CODE IN THE REBUILD MODULE... *
'* *
'************************************************* **********
'************************************************* ***
'* Rebuild the form *
'************************************************* ***
'* p_Rebuild_Form _
'* sFormName:=c_sFormName, _
'* sCaption:=c_sCaption, _
'* bShowModal:=False, _
'* bEnabled:=True, _
'* lBackColor:=vbBlue, _
'* lForeColor:=vbYellow, _
'* sTag:=c_sTag, _
'* iZoom:=100, _
'* iTop:=iTop, _
'* iLeft:=iLeft, _
'* iHeight:=iHeight, _
'* iWidth:=iWidth

'************************************************* **********
'* 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)

'OBJECTS DECLARATIONS
Dim oForm As Object

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

'Update the FORM Properties
With oForm

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

'FORM: BEHAVIOR PROPERTIES
'Use SHOWMODAL = TRUE for form that must have
'all of the focus and when the user must be
'restristed in which form can be selected.
'Use SHOWMODAL = FALSE for when multiple forms
'are on display and the user can select any for
'that the user wants.
.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

'Let the operating system catch up
VBA.DoEvents

End Sub

Thanks.
Reply With Quote
  #5  
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

Thread Tools
Display Modes


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 - Senior Forums

All times are GMT -7. The time now is 10:02 PM.


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