简体   繁体   中英

Creating Form Control at Cell Location with VBA in Excel

Reference

I am using ActiveSheet.Buttons.Add() to add format control buttons to a worksheet. This method suffers when I have to add several buttons with a certain horizontal distance between them and column widths change, causing a slight drift between buttons.

I would like to instead use a cell reference which would prevent this drifting caused by column width changes.

The syntax is

ActiveSheet.Buttons.Add BUTTON_LEFT, BUTTON_TOP, _
BUTTON_WIDTH, BUTTON_HEIGHT

This will create a button at the active cell. Change as possible.

ActiveSheet.Buttons.Add ActiveCell.Left, ActiveCell.Top, _
ActiveCell.Width, ActiveCell.Height 

EDIT : Beaten by Tim!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM