Excel中的宏、VBA

news/2024/7/21 7:35:11 标签: 前端, excel

excel-宏?">一、宏是什么?

EXCEL MACRO 是一种记录和播放工具,它仅记录您的 Excel 步骤,并且宏将根据需要播放任意多次。 VBA 宏可自动执行重复任务,从而节省了时间。 这是一段可在 Excel 环境中运行的编程代码,但您无需成为编码器即可对宏进行编程。 但是,您需要 VBA 的基础知识才能在宏中进行高级修改。

作为人类,我们是习惯的产物。 我们每天每个工作日都会做某些事情。 如果有某种神奇的方法可以按一个按钮并且完成了我们所有的例行任务,这会更好吗? 我能听到你说是的。 宏可以帮助您实现这一目标。 用外行语言来说,宏定义为您在 Excel 中的常规步骤的记录,您可以使用单个按钮进行重放。

例如,您正在作为自来水公司的出纳员。 一些客户通过银行付款,最终,您需要从银行下载数据并以符合业务需求的方式对其进行格式化。

您可以将数据导入 Excel 和格式。 第二天,您将需要执行相同的仪式。 它将很快变得无聊和乏味。 宏通过自动执行此类常规任务解决了此类问题。 您可以使用宏来记录以下步骤

  • 导入数据
  • 对其进行格式化以满足您的业务报告要求。

二、VBA是什么

VBA 是 Visual Basic for Applications 的缩写。 这是一种编程语言,Excel 在执行日常任务时会使用它来记录您的步骤。 您无需成为程序员或技术人员就可以享受 Excel 中宏的好处。 Excel 具有自动为您生成源代码的功能。 阅读有关 Vba 的文章以了解更多详细信息。

宏是开发人员功能之一。 默认情况下,开发人员选项卡不显示在 excel 中。 您需要通过自定义报告显示它

攻击者可以使用宏来破坏您的系统。 默认情况下,它们在 excel 中被禁用。 如果需要运行宏,则将需要启用运行宏,并且仅运行您知道来自受信任来源的宏

如果要保存宏,则必须将工作簿保存为启用宏的格式* .xlsm

宏名称不得包含任何空格。

创建宏时,请务必填写宏的描述。 这将帮助您和其他人了解宏在做什么。

我们将使用宏 excel 重要性中描述的方案进行工作。 我们将使用以下 CSV 文件。

Introduction to Macros in Excel

您可以在此处下载以上文件

我们将创建一个启用宏的模板,该模板将导入上述数据并对其进行格式化,以满足我们的业务报告要求。

## 启用开发者选项

要执行 VBA 程序,您必须有权访问 Excel 中的开发人员选项。 如下所示启用开发人员选项,然后将其固定到 Excel 中的主要功能区。

步骤 1)转到主菜单“文件”

选择选项“选项”。

How to Write Macros in Excel

What is VBA?

步骤 2)现在将打开另一个窗口,在该窗口中执行以下操作

  • 单击自定义功能区
  • 将复选框标记为开发人员选项
  • 点击确定按钮

How to Write Macros in Excel

步骤 3)开发人员标签

现在,您将能够在功能区中看到“开发人员”选项卡

How to Write Macros in Excel

步骤 4)下载 CSV

首先,我们将看到如何在电子表格上创建命令按钮并执行程序。

  • 在驱动器 C 中创建一个名为 Bank Receipts 的文件夹
  • 粘贴您下载的 receives.csv 文件

How to Write Macros in Excel

步骤 5)记录宏

  1. 单击开发人员选项卡
  2. 单击记录宏,如下图所示

How to Write Macros in Excel

您将获得以下对话窗口

Introduction to Macros in Excel

  1. 输入 ImportBankReceipts 作为宏名称。
  2. 第二步将默认存在
  3. 输入说明,如上图所示
  4. 点击“确定”标签

步骤 6)执行您要记录的宏操作/步骤

  • 将光标放在单元格 A1 中
  • 单击数据选项卡
  • 单击“获取外部数据”功能区栏上的“来自文本”按钮

You will get the following dialogue window

How to Write Macros in Excel

  1. 转到存储 CSV 文件的本地驱动器
  2. 选择 CSV 文件
  3. 点击导入按钮

您将获得以下向导

Introduction to Macros in Excel

完成上述步骤后,单击“下一步”按钮

Introduction to Macros in Excel

请按照上述步骤操作,然后单击下一步按钮

Introduction to Macros in Excel

  • 点击完成按钮
  • 您的工作簿现在应如下所示

Introduction to Macros in Excel

步骤 7)格式化数据

将列设为粗体,添加总计,然后使用 SUM 函数获取总计。

How to Write Macros in Excel

步骤 8)停止录制宏

现在我们已经完成了日常工作,我们可以单击停止录制宏按钮,如下图所示

How to Write Macros in Excel

步骤 9)重播宏

在保存工作簿之前,我们将需要删除导入的数据。 我们将执行此操作以创建一个模板,该模板将在每次我们有新的收据并要运行 ImportBankReceipts 宏时复制。

  • 突出显示所有导入的数据
  • 右键单击突出显示的数据
  • 点击删除
  • 单击另存为按钮
  • 将工作簿保存为启用宏的格式,如下所示

How to Write Macros in Excel

  • 复制新保存的模板
  • 打开它
  • 单击开发人员选项卡
  • 单击宏按钮

You will get the following dialogue window

Introduction to Macros in Excel

  1. 选择 ImportBankReceipts
  2. 突出显示您的宏的描述
  3. 点击运行按钮

您将获得以下数据

Introduction to Macros in Excel

恭喜,您刚刚在 excel 中创建了第一个宏。

​​​​​​​三、总结

宏通过使我们执行的大多数日常工作自动化来简化我们的工作生活。 Excel 中的宏由 Visual Basic for Applications 驱动。

To execute VBA program, you have to have access to developer option in Excel. Enable the developer option as shown below and pin it into your main ribbon in Excel.

**Step 1)**Go to main menu "FILE"

Select option "Options."

How to Write Macros in Excel

What is VBA?

**Step 1)**Go to main menu "FILE"

Select option "Options."

Step 2) Now another window will open, in that window do following things

  • 单击自定义功能区
  • 将复选框标记为开发人员选项
  • 点击确定按钮

How to Write Macros in Excel

Step 2) Now another window will open, in that window do following things

  • 单击自定义功能区
  • 将复选框标记为开发人员选项
  • 点击确定按钮

Step 3) Developer Tab

You will now be able to see the DEVELOPER tab in the ribbon

How to Write Macros in Excel

Step 3) Developer Tab

You will now be able to see the DEVELOPER tab in the ribbon

Step 4) Download CSV

First, we will see how we can create a command button on the spreadsheet and execute the program.

  • 在驱动器 C 中创建一个名为 Bank Receipts 的文件夹
  • 粘贴您下载的 receives.csv 文件

How to Write Macros in Excel

Step 4) Download CSV

First, we will see how we can create a command button on the spreadsheet and execute the program.

Step 5) Record Macro

  1. 单击开发人员选项卡
  2. 单击记录宏,如下图所示

How to Write Macros in Excel

You will get the following dialogue window

Introduction to Macros in Excel

  1. 输入 ImportBankReceipts 作为宏名称。
  2. 第二步将默认存在
  3. 输入说明,如上图所示
  4. 点击“确定”标签

Step 5) Record Macro

  1. 单击开发人员选项卡
  2. 单击记录宏,如下图所示

Step 6) Perform Macro Operations/Steps you want to record

  • 将光标放在单元格 A1 中
  • 单击数据选项卡
  • 单击“获取外部数据”功能区栏上的“来自文本”按钮

You will get the following dialogue window

How to Write Macros in Excel

  1. 转到存储 CSV 文件的本地驱动器
  2. 选择 CSV 文件
  3. 点击导入按钮

You will get the following wizard

Introduction to Macros in Excel

Click on Next button after following the above steps

Introduction to Macros in Excel

Follow the above steps and click on next button

Introduction to Macros in Excel

  • 点击完成按钮
  • 您的工作簿现在应如下所示

Introduction to Macros in Excel

Step 6) Perform Macro Operations/Steps you want to record

  • 将光标放在单元格 A1 中
  • 单击数据选项卡
  • 单击“获取外部数据”功能区栏上的“来自文本”按钮

Step 7) Format the Data

Make the columns bold, add the grand total and use the SUM function to get the total amount.

How to Write Macros in Excel

Step 7) Format the Data

Make the columns bold, add the grand total and use the SUM function to get the total amount.

Step 8) Stop Recording Macro

Now that we have finished our routine work, we can click on stop recording macro button as shown in the image below

How to Write Macros in Excel

Step 8) Stop Recording Macro

Now that we have finished our routine work, we can click on stop recording macro button as shown in the image below

Step 9) Replay the Macro

Before we save our work book, we will need to delete the imported data. We will do this to create a template that we will be copying every time we have new receipts and want to run the ImportBankReceipts macro.

  • 突出显示所有导入的数据
  • 右键单击突出显示的数据
  • 点击删除
  • 单击另存为按钮
  • 将工作簿保存为启用宏的格式,如下所示

How to Write Macros in Excel

  • 复制新保存的模板
  • 打开它
  • 单击开发人员选项卡
  • 单击宏按钮

You will get the following dialogue window

Introduction to Macros in Excel

  1. 选择 ImportBankReceipts
  2. 突出显示您的宏的描述
  3. 点击运行按钮

You will get the following data

Introduction to Macros in Excel

Congratulations, you just created your first macro in excel.

Step 9) Replay the Macro

Before we save our work book, we will need to delete the imported data. We will do this to create a template that we will be copying every time we have new receipts and want to run the ImportBankReceipts macro.


http://www.niftyadmin.cn/n/5028215.html

相关文章

【Qt】Qt中关联容器QMap,QMultiMap,QHash,QMultiHash 的理解

在Qt中,有几种关联容器可供选择: QMap:QMap是一个关联容器,存储键-值对,并根据键自动进行排序。它提供了快速的查找和插入操作,适用于需要根据键进行排序和搜索的场景。 QMultiMap:QMultiMap是…

利用芯片74hc165为单片机增加输入扩展端口proteus仿真arduino

我们前面的博文《输入端口少如何扩展?74hc148或74ls148级联在arduino中实现16转4的应用》介绍了148,148输入后可以立即输出到数码管,可以说它是自带编BCD编码器的。而今天这里我们主要介绍的74hc165是没有编码器,这里我们以proteus为仿真环境…

服务器免密登录设置

例如服务器A想要免密连接服务器B,需要以下2个步骤 步骤1:在服务器A上执行命令ssh-keygen –t rsa,直接回车,会在默认路径/root/.ssh下生成私钥和公钥 步骤2:将服务器A上生成的公钥id_rsa.pub的内容,复制粘…

深度学习-卷积神经网络-卷积图像去噪边缘提取-卷积与边缘提取[北邮鲁鹏]

目录标题 参考学习链接什么是图像边缘?为什么研究边缘?有哪些边缘种类?表面法向不连续深度不连续表面颜色不连续光照不连续 如何检测边缘?图像求导图像梯度图像梯度的方向图像梯度的模 噪声的影响噪声影响带来的问题解决办法&…

第二章:25+ Python 数据操作教程(第二十一节PIP连接错误:SSL 证书验证失败解决办法)

在公司网络中安装 python 包时最常见的问题是 SSL 证书验证失败。有时公司会屏蔽网络中的某些网站,因此员工无法访问这些网站。每当他们尝试访问这些网站时,都会显示“由于公司政策,访问被拒绝”。它会导致到达主要 python 网站时出现连接错误…

景联文科技:数据供应商在新一轮AI热潮中的重要性

景联文科技是AI基础行业的头部数据供应商,可协助人工智能企业解决整个人工智能链条中数据标注环节的相对应问题。 随着全球新一轮AI热潮来袭,大量训练数据已成为推动AI算法模型进步和演化的不可或缺的重要因素。数据的质量和数量直接影响了模型训练和性能…

Pytorch模型转ONNX部署

开始以为会很困难,但是其实非常方便,下边分两步走:1. pytorch模型转onnx;2. 使用onnx进行inference 0. 准备工作 0.1 安装onnx 安装onnx和onnxruntime,onnx貌似是个环境。。倒是没有直接使用,onnxruntim…

HarmonyOS/OpenHarmony应用开发-DevEco Studio新建项目的整体说明

一、文件-新建-新建项目 二、传统应用形态与IDE自带的模板可供选用与免安装的元服与IDE中自带模板的选择 三、以元服务,远程模拟器为例说明IDE整体结构 1区是工程目录结构,是最基本的配置与开发路径等的认知。 2区是代码开发与修改区,是开发…