15、Excel VBA:与其他 Office 程序交互的强大功能

Excel VBA:与其他 Office 程序交互的强大功能

1. Excel VBA 与其他 Office 程序交互概述

所有的 Microsoft Office 应用程序都使用 VBA 作为其底层宏语言,并且都有自己的对象模型,就像 Excel 一样。这使得 Excel VBA 在驱动其他 Office 程序方面比非 Microsoft 编程语言具有巨大优势。例如,你可以在 Excel 中创建一个 Word 文档,而无需在屏幕上打开 Word。

1.1 使用 Excel 创建 Word 文档

1.1.1 添加对象库引用

要使用 VBA 的 CreateObject 方法创建 Word 文档,首先需要在应用程序中添加对 Microsoft Word 对象库的引用。操作步骤如下:
1. 从菜单中选择“工具”|“引用”。
2. 在弹出的对话框中,选择“Microsoft Word 对象库”,并勾选旁边的复选框。
3. 点击“确定”,即可在 VBA 中使用 Word。

1.1.2 示例代码

以下是一个创建新 Word 文档并保存到本地硬盘的示例代码:

Sub Test_Word()
    Dim oWd As Word.Application, oWdoc As Word.Document
    Set oWd = CreateObject("Word.Application")
    Set oWdoc = oWd.Documents.Add
    oWdoc.Sections(1).Range.T

相关推荐

AI+VBA 30分钟打造Excel数据自动化处理系统

数据自动化处理是现代办公效率提升的核心技术,其原理在于通过程序化手段替代人工重复操作,实现数据的自动清洗、校验与转换。该技术的核心价值在于将业务人员从繁琐、易错的手动劳动中解放出来,显著提升数据处理的准确性与一致性,并降低人力成本。在应用场景上,尤其适用于企业内高频、规则明确的报表整理、人员信息录入、客户数据清洗等办公自动化任务。本文聚焦于利用VBA与AI大模型的组合优势,快速构建定制化数据处理流水线。VBA作为原生嵌入Office的脚本语言,能无缝操作Excel文件,执行具体的读写与流程控制;而AI大模型

weixin_30847865的博客 327

Excel/WPS VBA自定义函数实战:从原理到部署的完整指南

在数据处理领域,函数是封装计算逻辑的核心单元,它通过预定义规则将输入转换为输出,实现计算过程的抽象与复用。其工作原理基于参数传递与返回值机制,确保计算的可预测性。自定义函数的技术价值在于突破软件内置功能限制,允许用户根据特定业务逻辑定制计算规则,从而提升数据处理的自动化水平与准确性。在Excel或WPS表格等电子表格应用场景中,面对复杂业务计算、数据清洗或动态报表生成等需求,内置函数往往无法满足。通过VBA(Visual Basic for Applications)编程,用户可以创建自定义公式函数(UDF

weixin_34199335的博客 417

VBA表格循环操作:高效处理Excel与Word数据

表格数据处理是办公自动化的核心需求,VBA作为Office内置的编程语言,通过循环结构实现批量操作。For Each、For...Next和Do While三种循环方式分别适用于集合遍历、索引访问和条件循环场景。在Excel中,结合SpecialCells定位和数组处理可提升性能;Word表格需注意文本特殊字符处理。典型应用包括数据清洗、格式批量调整和跨表汇总,某电商案例显示VBA能将3小时人工操作缩短至10秒。掌握循环边界控制、错误处理和性能优化技巧(如禁用屏幕刷新、数组读写)是提升自动化效率的关键。

java2000.net 411

Excel上标全攻略:字符级格式、CHAR函数与VBA自动化

上标(Superscript)是Excel中实现专业文本表达的基础排版能力,本质为字符级格式属性,用于标识幂次、单位系数、脚注编号等语义化附属信息。其原理涉及Unicode字符编码、字体渲染机制与Excel三层格式结构(字符层/单元格层/内容层)。技术价值在于提升数据可读性、保障跨平台一致性及满足出版级规范要求。典型应用场景包括化学式(如H₂O)、数学公式(如x²+y²=1)、财务单位(如×10⁴)及科研文档标注。本文深入解析手动字符格式、CHAR函数伪造上标、VBA批量自动化三大路径,并覆盖字体兼容性、打

B1334628598的博客 563

EXCEL VBA从入门到精通 第一章:VBA入门

在VBA中,需要使用关键字Dim来定义一个变量,后面跟上变量名和变量的数据类型。例如,下面的代码定义了一个整型变量x和一个字符串变量name在VBA中,使用关键字Const来定义常量,后面跟上常量名和常量的值。例如,下面的代码定义了一个整型常量MAX_NUM和一个字符串常量MESSAGE需要注意的是,常量一旦被定义,其值就不能被改变。

1万+

英飞凌TC397芯片时钟树详解:从EB-tresos配置到PLL锁相环实战避坑

本文详细解析了英飞凌TC397芯片的时钟树架构,从EB-tresos配置到PLL锁相环的实战应用,帮助工程师避免常见配置陷阱。文章深入探讨了时钟源层、频率转换层和分配网络层的设计原理,提供了PLL配置的数学公式和EB-tresos关键容器的配置要点,并分享了调试技巧与性能优化实践,适用于MCU开发中的时钟管理需求。

weixin_42524226的博客 213

NVIDIA DGX Spark实战:如何在桌面上轻松运行200B参数大模型(附配置教程)

本文提供了NVIDIA DGX Spark在桌面端运行200B参数大模型的完整实战指南。详细介绍了从硬件初始化、系统配置、容器化环境搭建,到模型加载、量化、推理流水线编写及性能调优的全过程。重点阐述了如何利用其统一内存架构和TensorRT-LLM等工具进行高效本地推理,并探讨了通过双机互联扩展以应对超大规模模型的方法。

i3j4k5的博客 785

别再硬拔了!用这3个终端命令轻松搞定Mac上移动硬盘‘被程序占用’的问题

本文介绍了3个终端命令解决Mac上移动硬盘‘被程序占用’的问题,包括使用`diskutil list`定位硬盘、`lsof`查找占用进程以及`diskutil unmount`安全卸载。这些方法能有效避免数据风险,提升操作效率,特别适合开发者和技术爱好者。

weixin_33507732的博客 297

Keil MDK编译错误#541解决方案与ARM_Compiler包解析

在嵌入式开发中,编译器工具链的依赖管理是确保项目顺利构建的关键环节。以Keil MDK为例,其软件包依赖机制通过组件化设计实现功能解耦,其中ARM_Compiler包专门处理系统IO重定向等编译器扩展功能。这种架构既提升了模块复用性,也带来了版本兼容性挑战。当出现'Error #541: component missing'报错时,通常是由于中间件组件(如文件系统)在新版本中显式依赖了ARM_Compiler包。开发者需要通过Pack Installer安装该包,并在Run-Time Environment

weixin_32129187的博客 372

PXE 批量安装 Ubuntu 20.04

原文链接:https://www.cpweb.top/1698 一、介绍   Ubuntu 20.04 的服务器安装程序支持新的操作模式:自动安装(automated installation)。自动安装可以通过自动安装配置提前回答所有这些配置问题,并使安装过程无需任何交互即可运行。   在 Ubuntu 18.04 中,用的应答文件是 preseeds(预配置文件),它基于 debian-installer(aka di)来实现自动安装的。需要注意的是,如果你使用的是 cobbler,那你应....

supahero的博客 1万+

从稳压管到LDO芯片:一张图看懂线性电源的‘内卷’进化史

本文追溯了从稳压管到LDO芯片的线性电源技术进化历程,详细解析了各阶段的技术突破与局限。重点探讨了现代LDO在超低功耗、高精度控制等方面的创新,并提供了实战选型的黄金法则,帮助工程师在电子设备小型化与低功耗化趋势中做出最优选择。

weixin_42525551的博客 208

STK相关总结

STK简介 一.SIM卡应用工具包(SIM Application Toolkit),又名CAT/USAT,它包含一系列终端与SIM卡的交互指令,SIM卡可以应用卡内的小应用程序和终端交互,从而实现增值服务的目的,STK包括三种类,STK-imsi切换,STK –OTA,STK-BIP 功能: (1) Profile download:配置下载,开机初始化SIM卡过程中,终端告诉SIM卡终端支持哪些功能,STK中download指终端将数据发送给SIM卡 (2) Proactive command: 主动式

jingjing_2的博客 3360

Unitree G1仿人机器人协同搬箱:从仿真搭建到多机协同部署完整指南

Unitree G1仿人机器人协同搬箱技术方案摘要 本文提供了一套完整的Unitree G1人形机器人协同搬箱解决方案,涵盖从仿真环境搭建到多机协同部署的全流程。核心内容包括: 双仿真环境配置:同时搭建Gazebo+ROS Noetic基础仿真环境与Isaac Gym+Mujoco高性能RL训练环境,支持Sim2Sim迁移验证 训练框架搭建:详细配置unitree_rl_gym框架,提供PPO算法定制化训练流程和参数优化方案 数据集应用:整合宇树开源真机数据集(UnifoLM-WBT-Dataset)~~~

huanghm88的专栏 477

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

上一篇: 14、Excel 2007 VBA宏编程核心对象与操作详解
下一篇: 16、Excel VBA:图表、数据库与 API 调用全解析
电竞养老选手
博客等级 码龄4年 61粉丝 1196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值