在Excel中创建删除线宏 [英] Creating Strikethrough Macro in Excel
问题描述
我一直在寻找体面的文档,但尚未找到任何内容。 / p>
这是一些代码。
此外,我想知道VBA中最佳文档的位置。
Sub strikeOut()
Selection.Font.Strikethrough = True
End Sub
我也需要帮助命令按钮。
谢谢。
看起来你在正确的道路上。根据你的代码,我假设你已经有一个命令按钮创建。如果是这样的话:
Sub strikeOut()
With Selection.Font
.Strikethrough = Not。 Strikethrough
End with
End Sub
创建一个命令按钮: p>
- Excel 2003及更早版本:
- 打开
Visual Basic
工具栏,并激活控制工具箱
按钮。另一个框/工具栏应该出现不同的控制选项。 - 选择
按钮
选项,并将其放置在所需的位置。
- 打开
- Excel 2007及更高版本:
- 点击在
开发者
标签/功能区。 - 选择
插入
并选择按钮
并将其放置在所需的位置。
- 点击在
- *以下步骤适用于此时所有版本。
- 右键单击您的新按钮,然后选择
属性
为您的按钮提供名称/标题。
- 右键单击您的新按钮,然后选择
- 再次右键单击并选择
查看代码
。 - 在
ButtonName_Click()
sub中,使用以下方法之一添加strikeOut()
调用:
-
Call strikeOut()
-
- 或简单
-
strikeOut
-
为了回答你的问题的第二部分,很难说出什么是最好的,但这里有一些可能有帮助的链接:
I'm a novice to VBA and I'm trying to make a simple macro where one can highlight a set of cells, click a button, and strikethrough the selected sells. After, you can select the cell again, click the same button, and remove the strikethrough.
I have been looking for decent documentation but, have yet to find anything.
Here's some code.
Also, I would love to know where the best documentation is on VBA.
Sub strikeOut()
Selection.Font.Strikethrough = True
End Sub
I also need help with the command button.
Thank you.
It looks like you're on the right path. Based on your code, I'm assuming you already have a command button created. If so try this:
Sub strikeOut()
With Selection.Font
.Strikethrough = Not .Strikethrough
End With
End Sub
To create a command button:
- Excel 2003 and earlier:
- Open up the
Visual Basic
toolbar and activate theControl Toolbox
button. Another box/toolbar should appear with different control options. - Select the
Button
option and place it in the desired location.
- Open up the
- Excel 2007 and later:
- Click on the
Developer
tab/ribbon. - Select
Insert
and selectButton
and place it in the desired location.
- Click on the
- *The steps below apply to all versions from this point forward.
- Right-click on your new button and select
Properties
to give your button a name/caption.
- Right-click on your new button and select
- Right-click again and select
View Code
. - In the
ButtonName_Click()
sub, add thestrikeOut()
call using either:Call strikeOut()
- or simply
strikeOut
To answer the second part of your question, it's hard to say what is the 'best' but here are some links that may help:
Chip Pearson's site
MSDN
OZgrid
这篇关于在Excel中创建删除线宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!