McAfee 从 VBA 模块中删除代码
我正在尝试对 Excel 模块进行编程,在该模块中,它以在设计时创建的表单动态地将代码插入到新对象中。
我正在使用此代码,其中“Code”包含一个字符串,其中包含应进入 DstrFiles 对象的实际代码。
Dim DstrFiles As Object
Set DstrFiles = ThisWorkbook.VBProject.VBComponents("DistributeFiles")
With DstrFiles.CodeModule
.InsertLines .CountOfLines + 1, Code
End With
我的问题是,当我使用 .InsertLines 时,McAfee 会从我的模块中删除整个代码,有没有办法解决这个问题?
首先,我使用以下命令创建标签:
Form1.Controls.Add("Forms.Label.1", "Label1", True)
然后,我使用 .InsertLines 创建一些与标签配合使用的代码。
例如,我希望当有人单击标签时标签的背景颜色变为红色。 使用“.InsertLines”可以很容易地实现这一点。
解决这个问题的一种丑陋方法是预先创建一堆在后台准备好的代码,然后限制可以动态创建的标签数量。 - 我希望事情不会发展到那个地步。
我一直在谷歌搜索,这似乎是迈克菲的一个已知问题。
有谁知道创建动态用户表单的方法,该表单可以将代码添加到使用 Contrls.Add 方法添加的新标签或按钮中?
I am trying to program an Excel module where it dynamically inserts code in new objects in a form that is created at design time.
I am using this code where "Code" contains a string with the actual code that should go into the DstrFiles object.
Dim DstrFiles As Object
Set DstrFiles = ThisWorkbook.VBProject.VBComponents("DistributeFiles")
With DstrFiles.CodeModule
.InsertLines .CountOfLines + 1, Code
End With
My problem is that when I use the .InsertLines, McAfee removes the entire Code from my module, is there a way to work around this?
First I create the label with:
Form1.Controls.Add("Forms.Label.1", "Label1", True)
Then I use the .InsertLines to create some code to go with the Label.
For instance, I want the background color of the label to turn red when someone clicks on it. This has been very easy to accomplish with the ".InsertLines".
An ugly way to work around this is to just create a bunch of code beforehand that is ready in the background and then limit the amount of labels that may be created on the fly. - I hope it won't come to that.
I have been googeling around, and this seems to be a known problem with McAfee.
Do anyone know a way to create a dynamic user form that can add code to new labels or button that are added with the Contrls.Add method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果可能的话,我建议不要动态生成代码(听起来像自修改程序?)。
如果不知道您的具体问题,可能很难说,但我敢打赌,使用具有必要参数的函数有更好的解决方案。
If possible I would recommend against dynamic generation of code (smells like a self-modifying program?).
It's maybe hard to say without knowing your specific problem but I bet there is a better solution using a function with the necessary parameters.
您或许可以解决此版本的 McAfee。 但下一个版本的数据文件或其他恶意软件拦截器可能会阻止您。
因此,您可以创建这样的代码以在您的开发计算机上运行,但在分发给客户时它永远不会(或只是暂时)工作。
You might be able to workaround this version of McAfee. But the next version of the data-files, or another malware blocker might block you anyhow.
So you can create code like this to run on you development machine, but it will never (or only temporary) work when distributed to customers.
您不应该通过编写创建控件的代码来生成新标签。
您应该使用 Controls 集合上的 .Add 方法来创建新标签。
例如:
您可以使用
WithEvents
来获取事件。例如,在 UserForm1 中,
如果要创建新添加的控件的动态数组,则需要创建一个小包装类。 示例代码位于此处。
You should not be generating new labels by writing code that creates the controls.
You should be using the .Add method on the Controls collection to create new labels.
For example:
You can use
WithEvents
to get the events.For example, in UserForm1,
If you want to make a dynamic array of newly added controls, you'll need to create a little wrapper class. Sample code for that is here.