python win32com vba用户形对象字幕属性集
我正在尝试使用Python中的Win32COM创建Excel VBA用户形式。我能够将用户形式添加到工作簿中,甚至可以将控件添加到此表单中,但是我坚持更新用户形象对象本身的属性。例如:我可以使用以下代码阅读字幕属性,但是我没有运气设置它。 有人知道如何使用Win32COM在Python中设置VBA用户形式属性吗?
我的代码:
import win32com.client as win32
com_object = win32.gencache.EnsureDispatch('Excel.Application')
xlFile = com_object.Workbooks.Open(Filename = 'MyExcelFileaPath.xlsx')
xlForm = xlFile.VBProject.VBComponents.Add(3)
print (xlForm.Properties('Caption')) #this works
xlForm.Properties('Caption') = 'Custom Caption' #this does not work - error: SyntaxError: can't assign to function call
xlForm.Properties.Caption = 'Custom Caption' #this does not work
I am trying to create Excel VBA UserForm using Win32com in Python. I am able to add the UserForm to a workbook, I can even add controls to this form, however I am stuck with updating the properties of the UserForm object itself. For example: I can read the Caption property using the below code, but I had no luck setting it.
Does anyone know how to set VBA UserForm properties in Python using win32com?
My Code:
import win32com.client as win32
com_object = win32.gencache.EnsureDispatch('Excel.Application')
xlFile = com_object.Workbooks.Open(Filename = 'MyExcelFileaPath.xlsx')
xlForm = xlFile.VBProject.VBComponents.Add(3)
print (xlForm.Properties('Caption')) #this works
xlForm.Properties('Caption') = 'Custom Caption' #this does not work - error: SyntaxError: can't assign to function call
xlForm.Properties.Caption = 'Custom Caption' #this does not work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,经过一周的研究,反复试验,我想出了一种设置用户形象对象属性的方法。正如我所怀疑的那样,答案有点愚蠢:
希望这可以帮助某人节省一些时间。
Finally, after a week of research, trial and error I came up with a way to set UserForm object's properties. As I suspected, the answer is kind of silly:
Hope this helps someone to save some time.