I have a VB 6 Add-in that adds all the projects to a project group, iterates through each of the component of those projects, and if a form or usercontrol is found then changes its properties.
The properties are defined by the user. If user wants to change the height of all the forms or usercontrol then the code snippet is as follows
Private Sub Update_ButtonClick()
'..declaring all the variables here
' VBInstance is initialized to VBIDE.VBE when the add-in is loaded
For Index = 1 To projCount
compoCount = VBInstance.VBProjects(Index).VBComponents.Count
For jIndex = 1 To compoCount
csFileName = VBInstance.VBProjects(Index).VBComponents(jIndex).name
componentType = VBInstance.VBProjects(Index).VBComponents(jIndex).Type
If componentType = VBIDE.vbext_ct_VBForm Or componentType = VBIDE.vbext_ct_UserControl Then '.frm or .ctl
VBInstance.VBProjects(Index).VBComponents(jIndex).Properties(propChange).Value = propvalue 'changing the property
VBInstance.VBProjects(Index).VBComponents(jIndex).SaveAs csFileName 'Saving the file
End If
Next jIndex
Next Index
End Sub
Whenever I give the Properties name as Font, I get the error
Runtime error ‘425’ Invalid Object use
I have tried PropertyBag.WriteProperty from http://visualbasic.freetutes.com/learn-vb6-advanced/lesson13/p20.html but it does not serve my purpose.
Is there any way out to set the Font property of a control or form?
When I open the ctl or form in notepad, I cannot find the Font property in it so I cannot use text replacement here.
Can anyone help?
Updated Code :
Private Sub Update_ButtonClick()
Dim fobject As New StdFont
fobject.Name = "Arial"
Set propvalue = fobject
For Index = 1 To projCount
compoCount = VBInstance.VBProjects(Index).VBComponents.Count
For jIndex = 1 To compoCount
csFileName = VBInstance.VBProjects(Index).VBComponents(jIndex).Name
componentType = VBInstance.VBProjects(Index).VBComponents(jIndex).Type
If componentType = 5 Or componentType = 8 Then
VBInstance.VBProjects(Index).VBComponents(jIndex).Properties("Font").Value= propvalue
VBInstance.VBProjects(Index).VBComponents(jIndex).SaveAs csFileName
End If
Next jIndex
Next Index
End Sub
And the error that i got is
Run-time error '425':
Invalid object use
The
Fontproperty is an object, not an simple intrinsic value. You’ll need to useSetwith an appropriateStdFontobject assigned topropvalue.Alternatively, you can special case the font and just set the property’s
.Nameproperty to the required font name.