在单元格中放置一个命令按钮 MS Excel vba [英] Place a command button in a cell MS Excel vba

查看:34
本文介绍了在单元格中放置一个命令按钮 MS Excel vba的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 VBA 代码在单元格中放置一个命令按钮.说位置 B3.我为此使用了宏记录器,但它为我提供了按钮的顶部底部值.我不想要那个,因为如果我将我的代码带到其他具有其他屏幕分辨率的计算机上,代码将失败.单元格位置(示例 B3)将是一个绝对位置.

I want to place a command button in a cell though VBA code. Say position B3. I used macro recorder for this purpose but it gives me the top bottom values of the button. I don't want that cuz if I take my code to some other computer with another screen resolution, the code will fail. A cell position (example B3) will be an absolute position.

你能给我建议一种方法吗.

Can you suggest me a way to do this.

P.S 这是一个activeX按钮

P.S Its an activeX button

谢谢

推荐答案

您不能将任何对象放置在单元格中",只能放置在单元格上方.您可以将按钮的 Left 和 Top 属性设置为 Cell 的 Left/Top.

You can't place any object "in" a cell, only over it. You can set the button's Left and Top properties to the Cell's Left/Top.

Sub Tester()
    Dim rng As Range
    Set rng = ActiveSheet.Range("B3")
    With ActiveSheet.OLEObjects("CommandButton1")
        .Top = rng.Top
        .Left = rng.Left
        .Width = rng.Width
        .Height = rng.RowHeight
    End With
End Sub

这篇关于在单元格中放置一个命令按钮 MS Excel vba的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆