12、VBA Sub 过程的使用指南

VBA Sub 过程的使用指南

1. 过程概述

过程是一系列驻留在 VBA 模块中的 VBA 语句,可通过 Visual Basic Editor (VBE) 访问。一个模块可以包含任意数量的过程,每个过程包含一组用于完成特定任务的 VBA 语句,大多数 VBA 代码都包含在过程中。

过程可以通过多种方式调用或执行,通常从开始到结束执行,但也可以提前结束。建议避免创建执行多种不同操作的极长过程,可编写多个具有单一目的的较小过程,再设计一个主过程来调用这些小过程,这样便于代码维护。

有些过程被编写为接收参数,参数是过程使用的信息,在过程执行时传递给它,其工作方式类似于 Excel 工作表函数中的参数。过程内的指令使用这些参数执行操作,过程的结果通常基于这些参数。

2. 声明 Sub 过程

使用 Sub 关键字声明的过程必须遵循以下语法:

[Private | Public][Static] Sub name ([arglist])
    [instructions]
    [Exit Sub] 
    [instructions]
End Sub

以下是构成 Sub 过程的元素说明:
| 元素 | 说明 |
| ---- | ---- |
| Private | 可选。表示该过程仅可被同一模块中的其他过程访问。 |
| Public | 可选。表示该过程可被工作簿中所有其他模块中的所有其他过程访问。若在包含 Option Private Module 语句的模块中使用,该过程在项目外

如何利用VBA自动生成PPT报告 本文是继python(多级表头)之后的另一个项目,主要是利用VBA实现自动更新PPT模板的功能。主要是常规的PPT太多了, 不想把时间浪费在Ctrl+C 和Ctrl+V 之间,唯有想想自动化的可行性了; 一开始时候是希望用Python(pptx)来写的,但感觉这个包兼容性不够好,生成的图表不能和现有的图型一致,并且该数据模板的制作时间也很长,所以还是用回微软他家的程序好了。(实验证明,①编程都是有... 阅读详情

相关推荐

实用VBA:12.用VBA将txt文本文件导入Excel表格

小伙伴们工作中时常遇到处理文本文件的情况。有些业务系统中的数据记录、日志文件、格式化输出的数据等是以txt文本文件的方式记录的。但是在进行数据处理和分析时,如果需要处理大量的文本文件、或对文本文件中特定的字段、数据等进行处理,会显得繁琐而棘手。如果能够导入到excel文件中,就可以发挥Excel进行数据统计分析功能的优势。

周公笃行的博客 4582

Excel中VBA编程学习笔记(三)

  12、使用InputBox函数进行输入 语法如下: InputBox(prompt [,title] [,default] [,xpos] [,ypos] [,helpfile,context]) 参数说明: prompt为提示内容,必选; title对话框标题; default为对话框中缺省的文字内容; xpos和ypos表示对话框距离屏幕左上角的距离,缺省则居中. 使用示例...

数据之道 1825

12、VBA函数过程创建全解析

本文全面解析了VBA函数过程的创建与使用,涵盖Sub过程与函数过程的区别、自定义函数的创建原因及示例分析、函数语法结构、作用域设置、执行方式(包括在工作表公式、条件格式、VBA过程和立即窗口中的调用),并提供了常见错误解决方法与性能优化建议。通过流程图和对比表格直观展示开发流程与使用场景,帮助用户高效掌握VBA自定义函数的应用技巧,提升Excel自动化处理能力。

u6v7w8x的博客 43

STC8G1K08A的10位PWM避坑指南:为什么你的占空比调节总失效?(附寄存器操作时序图)

本文深入剖析了STC8G1K08A单片机10位PWM功能中占空比调节失效的核心原因,揭示了数据手册未明确指出的寄存器操作时序陷阱。通过对比错误与正确配置的波形,文章指出关键在于更新占空比高2位前需临时关闭PWM输出,并提供了经过验证的安全操作宏与函数库,帮助开发者彻底解决此问题,实现0%-100%的平滑控制。

yyy34的博客 761

TensorFlow GPU版本安装步骤-Windows系统

本文由在Windows下安装TensorFlow GPU版本教程-CSDN等整理得到。 目录 1、确认显卡是否支持CUDA 1.1 查看显卡信息 打开“设备管理器”,查看显卡信息,如下图所示: 由上图知,本电脑的显卡为NVIDIA Quadro P400. 1.2 查看支持CUDA的显卡 网址:https://developer.nvidia.com/cuda-gpus 经查询可知,该显卡支持CUDA,如下图所示: 2、安装CUDA 2.1 下载CUDA 网址:https://developer.nvi

x_lingyun的专栏 771

LabVIEW实战:3步搞定Excel模板数据填充(附完整VI源码)

本文提供了一个高效的LabVIEW Excel报表自动化方案,通过使用命名区域定位和动态文件管理,实现数据的精准、动态填充。文章详细阐述了如何构建可复用的数据填充引擎,包括文本、表格数据及图表的写入,并分享了主程序流程、错误处理及性能优化等进阶技巧,帮助工程师彻底摆脱手动操作,提升工作效率。

weixin_29233333的博客 282

雷达仿真:FMCW TDMA-MIMO 3D点云获取方法

2 信号建模摘要:通过设置时分复用(TDMA)波形结合FMCW毫米波雷达仿真获取目标的距离、速度和方位角3D点云信息。在本案例中,首先通过发射天线交替发射FMCW波形并通过接收天线依次接收回波信号从而得到雷达原始数据,其次对获取的原始数据依次经行距离、速度、角度估计从而输出目标的3D点云。阅读本文档,你将对TDMA-MIMO雷达的基本原理、毫米波雷达距离估计、速度估计以及角度估计的基本原理有所了解,另外CA-CFAR恒虚警以及MUSIC-DOA估计在本案例中也有所涉及。1 TDMA-MIMO原理。

Poulen的博客 6968

从工艺到器件:用Silvaco ATLAS仿真PIN二极管击穿电压的保姆级指南

本文详细介绍了使用Silvaco ATLAS仿真PIN二极管击穿电压的全流程指南,从工艺仿真基础搭建到器件结构构建,再到击穿特性仿真和结果分析。通过Silvaco工具链,工程师可以在设计阶段精准预测器件性能,优化击穿电压,提升研发效率。

weixin_34259816的博客 360

手把手教您windows如何正确的开启局域网共享,如何解决“没权限、空密码访问等诸多问题”,含手动操作教程 + 傻瓜式一键设置工具(局域网共享+打印机管理),二选一总有一款能满足您!

😫 Windows共享总失败?别抓狂!这篇教程带你破解“空密码”访问的核心难题 🔑,四步搞定所有设置。文末还附赠“一键修复”神器 🚀,让文件共享丝滑如德芙!

XiaoqiangClub的博客 1492

JAVA:Spring Boot 集成 Atomikos 实现分布式事务

摘要: Atomikos是一款基于JTA标准的分布式事务协调器,通过两阶段提交(2PC)协议实现跨数据库/消息系统的事务一致性,适用于金融等高要求场景。本文以Spring Boot集成Atomikos为例,演示多数据源(订单库、库存库)的分布式事务管理。核心步骤包括:引入Atomikos依赖、配置XA数据源、设置两阶段提交的MyBatis多数据源,并通过Atomikos协调全局事务,确保跨库操作原子性。代码示例涵盖配置类、YAML定义及MySQL XA数据源初始化,为分布式系统提供强一致性解决方案。

木头 337

OpenClaw 2026 路线图详解:3 大协作能力升级与社区贡献增长 62% 的实证分析

介绍 OpenClaw 2026 如何通过上下文锚定(Context Anchoring)、协作质量定义和责任边界机制,将 AI 编程工具从单点补全升级为嵌入代码生命周期的协作对齐系统,并详解 `.openclaw/config.yaml` 中 `context_anchor` 配置的实操方法与效果

weixin_42545292的博客 388

深度学习工具包 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")

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

上一篇: 34、扩散、缓冲与结合:细胞内钙动力学的奥秘
下一篇: 19、图像噪声模型及生成方法详解
python9snake
博客等级 码龄1天 0粉丝 1724原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址