如何在Microsoft Word中记录宏并自动执行繁琐的任务

Macros are basic bits of programming that let you hit a quick button or keyboard shortcut to trigger a pre-recorded action. Here’s how to make easy ones in Word.

宏是编程的基本位,可让您按快速按钮或键盘快捷键来触发预先记录的操作。 这是在Word中制作简单代码的方法。

什么是宏? (What Is a Macro?)

A macro is really just a recording of a series of button presses, clicks, and typing. When you record a macro, you just hit record, perform the steps you want to automate, stop the recording, let Word create the programming for you, and then assign the macro to a button or keyboard shortcut. Whenever you want to perform that series of actions in the future, you just activate the macro.

宏实际上只是一系列按钮按下,单击和键入的记录。 录制宏时,您只需单击记录,执行要自动执行的步骤,停止录制,让Word为您创建程序,然后将宏分配给按钮或键盘快捷键即可。 每当您以后想要执行一系列操作时,只需激活宏即可。

You can use macros for all kinds of things. Honestly, the possibilities are pretty much limitless. For example, you could set up a macro that creates a new footer with your company information, formats the text however you like, and even inserts page numbers. So, why not just do this using a template with some boilerplate text? Well, you can. But what happens when you have an existing document to which you want to add that stuff?

您可以将宏用于各种事物。 老实说,可能性几乎是无限的。 例如,您可以设置一个宏,用您的公司信息创建一个新的页脚,设置所需格式的文本,甚至插入页码。 那么,为什么不仅仅使用带有一些样板文本的模板呢? 好吧,可以。 但是,如果您有一个现有文档要向其中添加内容,该怎么办?

You could also create macros to insert already-formatted tables of a specific size, search for a specific paragraph style, or just insert some text.

您也可以创建宏以插入已格式化的特定大小的表,搜索特定的段落样式或仅插入一些文本。

We’re going to use the very basic example of inserting some text to walk you through how to record a macro. But use your imagination and experiment. You’ll be surprised how much you can do with them.

我们将使用一个非常基本的示例来插入一些文本,以引导您完成如何记录宏的操作。 但是要用你的想象力和实验。 您会惊讶于您能与他们做什么。

如何录制宏 (How to Record a Macro)

First, create a new blank Word document to work in. You’ll be able to save your macros in a system-wide database, so you don’t need to create new ones for each document you work on. In the blank document, switch to the “View” tab on the Ribbon, click the “Macros” dropdown menu, and then click the “Record Macro” command.

首先,创建一个新的空白Word文档进行处理。您将能够将宏保存在系统范围的数据库中,因此无需为每个要处理的文档创建新的宏。 在空白文档中,切换到功能区上的“查看”选项卡,单击“宏”下拉菜单,然后单击“记录宏”命令。

Next, give your macro an appropriate name and type a brief description. It’s an important step, especially if you’re planning on making a lot of macros. For our example, we’re going to create a kind of jokey text insertion that types the name: “Lwaxana Troi, Daughter of the Fifth House, holder of the Sacred Chalice of Rixx, heir to the Holy Rings of Betazed”—something we wouldn’t want to type over and over again if it were our full title.

接下来,给您的宏起一个适当的名称并输入简短描述。 这是重要的一步,特别是如果您打算制作很多宏。 对于我们的示例,我们将创建一种键入名称的jokey文本:“ Lwaxana Troi,第五宫之女,Rixx神圣圣杯的持有人,贝塔泽德圣戒的继承人” —如果这是我们的完整标题,则不想一遍又一遍地输入。

Choose whether to assign your macro to a button or keyboard shortcut. And finally, choose where to store your macro. The default is to store it in Word’s master template (a file named Normal.dotm) so that you can use it in all your documents. But, you can also store it only in the current document if you want. Click the “OK” button when you’re done.

选择是将宏分配给按钮还是键盘快捷键。 最后,选择存储宏的位置。 默认设置是将其存储在Word的主模板(名为Normal.dotm的文件)中,以便可以在所有文档中使用它。 但是,如果需要,您也可以仅将其存储在当前文档中。 完成后,单击“确定”按钮。

For the sake of this explainer, we’ll show you the creation process for both the button and keyboard. And note that you can always click the “Macros” menu button and edit these settings later if you want to change them.

为了便于说明,我们将向您展示按钮和键盘的创建过程。 并请注意,如果要更改设置,可以随时单击“宏”菜单按钮并在以后编辑这些设置。

If you choose the “Button” option, you’re presented with a screen that lets you choose where to store the new button. The default is to place it on the Quick Access Toolbar. Click the name of the macro in the left column, and then click the “Add” button to add the macro to the list of buttons for the toolbar shown on the right. When you’re done, click the “OK” button.

如果选择“按钮”选项,则会显示一个屏幕,让您选择将新按钮存储在何处。 默认是将其放置在快速访问工具栏上。 单击左栏中的宏名称,然后单击“添加”按钮以将宏添加到右侧所示工具栏的按钮列表中。 完成后,单击“确定”按钮。

If you’re assigning your macro to a keyboard shortcut, you’ll see the screen below instead. Make sure the name of the macro is selected in the “Commands” pane, click inside the “Press New Shortcut Key” box, and then press the keyboard combo you want to use. You can choose almost any combination of Ctrl, Alt, Shift, and any other primary key, but keep in mind that you’ll need one that isn’t already assigned to a Word or Windows/macOS shortcut.

如果您要将宏分配给键盘快捷键,则会看到下面的屏幕。 确保在“命令”窗格中选择了宏的名称,在“按新的快捷键”框内单击,然后按要使用的键盘组合键。 您几乎可以选择Ctrl,Alt,Shift和任何其他主键的任意组合,但是请记住,您将需要一个尚未分配给Word或Windows / macOS快捷方式的键。

For our jokey Star Trek macro, we’re going to hold Ctrl, then press L, let go of the L, and then press T—all without releasing Ctrl. The resulting shortcut is expressed as “Ctrl+L,T.” That multi-letter expansion is a way to avoid conflicts with common default shortcuts. When you’re done, click the “Assign” button, and then click the “Close” button.

对于我们的开玩笑星际迷航(Star Trek)宏,我们将按住Ctrl,然后按L,放开L, 然后按T,所有操作均不释放Ctrl。 产生的快捷方式表示为“ Ctrl + L,T”。 多字母扩展是一种避免与常见的默认快捷方式冲突的方法。 完成后,单击“分配”按钮,然后单击“关闭”按钮。

Now, you’re placed back in the main writing interface of Word. The program is in recording mode, so perform any actions you like. You can click buttons, open menus, insert objects—you name it. Word watches and records whatever you’re doing as a macro. And don’t worry about taking your time. Word doesn’t really duplicate these actions at the speed you’re performing them. Instead, it takes the actual actions you make, and creates a script to run them.

现在,您又回到了Word的主要编写界面中。 该程序处于录制模式,因此请执行您喜欢的任何操作。 您可以单击按钮,打开菜单,插入对象-为其命名。 Word监视并记录您作为宏所做的任何事情。 并且不用担心花费时间。 Word并没有真正按照您执行它们的速度来复制这些操作。 相反,它会执行您执行的实际操作,并创建一个脚本来运行它们。

For our example, we’re just repeating our rather nerdy name and title:

对于我们的示例,我们只是重复我们相当呆板的名称和标题:

While creating your macro, you can click the “Pause recording” button if you need to adjust something or make some quick notes. Click the “Resume recorder” button to continue working on your macro.

创建宏时,如果您需要调整某些内容或做一些快速注释,则可以单击“暂停录制”按钮。 单击“恢复记录器”按钮以继续处理宏。

When you’re done, open the “Macros” dropdown menu again, and then click the “Stop recording” command.

完成后,再次打开“宏”下拉菜单,然后单击“停止录制”命令。

That’s it. Word creates a macro from your recording and saves it as a button or keyboard shortcut (whatever you decided).

而已。 Word从您的录音中创建一个宏,并将其保存为按钮或键盘快捷键(无论您决定如何)。

To run the macro, click the button you assigned or the hit the keyboard shortcut you defined. If you chose the button option, you’ll see your macro button in the “Quick Access Toolbar” at the very top of the window.

要运行宏,请单击分配的按钮或单击定义的键盘快捷键。 如果选择了按钮选项,您将在窗口顶部的“快速访问工具栏”中看到宏按钮。

Obviously, this is a super simple example we’ve given you. You can use Word to create some pretty sophisticated macros. Advanced users can even manually program their own (or manually tweak their recorded macros). But this guide should at least get you started creating some basic macros.

显然,这是我们提供的一个非常简单的示例。 您可以使用Word创建一些非常复杂的宏。 高级用户甚至可以手动编程自己的程序(或手动调整其录制的宏)。 但是本指南至少应该让您开始创建一些基本的宏。

Image credit: Mopic/Shutterstock

图片来源: Mopic / Shutterstock

翻译自: https://www.howtogeek.com/343965/how-to-record-macros-and-automate-tiresome-tasks-in-microsoft-word/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值