MS Excel 2003 - 处理形状时 Excel VBA 中的简单取消选择问题
所以我有一个 Excel 工作簿,其中有一个全局映射方案。所以我在 Excel 中为每个国家/地区都有一个形状。根据区域选择,相对于数据/查询,它将以各种方式遮蔽区域/国家。
所以我知道如何在颜色、渐变阴影等方面操纵每个形状......
我不知道该怎么做是“取消选择”子例程末尾的形状。我的代码看起来像这样(非常简单):
sheet1.shapes("CountryName").select
selection.shaperange.fill.solid
selection.shaperange.fill.visible = true
selection.shaperange.fill.forecolor.rgb=rgb(110,110,110)
selection.shaperange.fill.onecolorgradiend msogradienthorizontal, 2, 0.45
好吧,从一个形状/国家/地区到另一个形状/国家/地区,“取消选择”并不是什么大不了的事情,因为焦点会跳跃,但最后???
我猜测/尝试了很多东西,但可惜没有运气,
谢谢!
So I have an excel workbook that has a global mapping scheme in it. So I have a shape for each and every country in excel. Depending on the region select, relative to the data/query, it will shade regions/countries in various ways.
So I know how to manipulate each shape in terms of colors, gradient shading, etc....
What I don't know how to do is "unselect" the shape at the end of the sub routine. My code looks like this (real simple):
sheet1.shapes("CountryName").select
selection.shaperange.fill.solid
selection.shaperange.fill.visible = true
selection.shaperange.fill.forecolor.rgb=rgb(110,110,110)
selection.shaperange.fill.onecolorgradiend msogradienthorizontal, 2, 0.45
ok so from one shape/country/region to another the "unselect" is not that big of a deal because focus jumps, but at the end????
I have guessed/tried a bunch of stuff but alas no luck
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的源代码最后一行有一个拼写错误,...gradiend --> ...渐变
“取消选择”形状对象的一种非常简单的方法是添加这行代码,
这会将焦点移动到工作表中的单元格 A1 ,从而远离您的对象。非常粗鲁,我不推荐这样做。我也不建议按照上面的建议“保存当前选择”,因为我们不知道光标是在单元格中还是在另一个(范围)对象中。
更好的方法是在整个脚本中完全避免“选择”。将您的形状分配给一个对象并操作该对象(注意:我在测试中使用第一个可用对象在sheet3中进行模拟),即
更好的是,如果您正在处理一个为您提供形状名称的列表,请执行以下
操作这有帮助
祝你好运麦克D
you have a typo in your source last line, ...gradiend --> ...gradient
a very simple way of "de-selecting" the shape object would be to add this line of code
this moves the focus to cell A1 in your sheet and hence away fro your object. Very rude, and I don't recommend it. I also don't recommend to "save the current selection" as proposed above as we don't know if the cursor is in a cell or at another (range) object.
The bettwer way is to avoid "selection" completely throughout your script. Asign your shape to an object and manipulate that object (note: I simulated in sheet3 with the first available object in my test), i.e.
Even better, if you are processing a list that gives you the name of a shape, do the following
Hope this helps
Good luck MikeD
您不能简单地记录所选的原始单元格吗?
更新:这一段代码记录了当前的选择,然后在选择范围(“A4”)后重新选择它。在不知道工作簿中有哪些形状的情况下,我无法验证这是否有效,但到目前为止我已经测试过了。
Can you not simply record the original cell which was selected?
Update: This bit of code records the current selection, then re-selects it after selecting range("A4"). Without knowing what kinds of shapes you have in your workbook, I can't verify that this will work, but it has so far with what I've tested.
我遇到了类似的问题,我需要在单击形状后隐藏它。我的解决方案是使用
SendKeys
来转义选择I ran into a similar problem where I needed to hide a shape after it was click. My solution was to use
SendKeys
to escape the selection