7、VBA编程入门:参数、对象属性与实用技巧

VBA编程入门:参数、对象属性与实用技巧

1. 参数相关知识

在VBA编程中,参数常常让新手感到困惑。有些方法使用参数来进一步明确要执行的操作,有些属性则使用参数来进一步指定属性值,而且在某些情况下,部分参数是可选的。

以工作簿对象的 Protect 方法为例,该方法需要三个参数: password 、 structure 和 windows ,这些参数对应“保护结构和窗口”对话框中的选项。

以下是使用 Protect 方法的示例:

' 使用密码保护工作簿,保护结构但不保护窗口
Workbooks("MyBook.xlsx").Protect "xyzzy", True, False

' 不使用密码保护工作簿,保护结构但不保护窗口
Workbooks("MyBook.xlsx").Protect , True, False

使用命名参数可以提高代码的可读性,例如:

Workbooks("MyBook.xlsx").Protect Structure:=True, Windows:=False

对于返回值的属性(和方法),必须在参数周围使用括号。例如, Range 对象的 Address 属性需要五个可选参数,以下是正确和错误的示例:

<
【 VBA 编程】3分钟掌握End属性:轻松定位数据边界 End属性用法及其使用案例 阅读详情

相关推荐

【Excel VBA 编程】针对表格操作,一键生成工资条,代码中仅修改3个参数

现在就教大家一招,即使是再多的数据也不怕,一键搞定,还不用求人,更不需要一次记住复杂的步骤和繁琐的Excel公式,关键是能学到编程知识还FOR^-^ FREE,你心动了吗

wei1019的专栏 1300

VBA代码解决方案第十三讲:如何利用VBA在单元格中录入公式

VBA代码解决方案》(版权10028096)这套教程是我最早推出的教程,目前已经是第三版修订了。这套教程定位于入门后的提高,在学习这套教程过程中,侧重点是要理解及掌握我的“。要灵活运用教程中的实例像搭积木一样把自己喜欢的代码摆好。这套教程共三册,一百四十七讲,内容覆盖较广,也是初级和中级间的过渡教程,改版后的内容主要是提供程序源码文件及代码修正为32位和64位兼用代码。今后一段时间会给大家陆续推出。今日的内容是VBA代码解决方案第十三讲:如何利用VBA在单元格中录入公式。

VBA语言専攻 2062

7、VBA编程中的对象变量、参数传递与类模块详解

本文深入探讨了VBA编程中的核心概念,包括变量声明与作用域、对象变量的早期与后期绑定、集合对象的使用、参数传递方式(ByRef与ByVal)及其性能对比、可选参数与ParamArray的应用、内置常量的优势,以及类模块在面向对象编程中的重要作用。通过详细示例展示了类模块的属性、方法、事件处理及简单继承多态实现,帮助开发者提升代码的可维护性、复用性和扩展性,适用于中高级VBA开发者学习与参考。

x8y9z0的博客 75

7、VBA编程:对象操作全解析

本文全面解析了VBA编程中的对象操作,涵盖对象的属性、方法、事件、集合和对象变量的使用,详细介绍了对象层次结构、Is运算符、With语句简化代码、Application对象应用,并通过综合案例展示自动化文档处理流程。同时提供了性能优化建议和错误处理机制,帮助开发者提升VBA程序效率与稳定性,是深入掌握Office自动化编程的实用指南。

alice7model的博客 53

掌握Access VBA编程:从入门到实践

本篇博客将带你深入了解Access VBA编程的基础知识,包括VBA模块和过程类型,Visual Basic编辑器(VBE)的使用,以及变量、函数、决策和循环的掌握。通过本章内容的探索,你将能够更好地管理数据库,实现自动化任务,提高工作效率。

weixin_30415591的博客 894

掌握VBA编程:条件语句与数组的使用

本文深入探讨了VBA编程中的条件语句(If...Then...ElseIf和Select Case)和数组的使用方法。通过对具体示例代码的分析,展示了如何使用这些结构来实现复杂的程序逻辑,同时强调了良好的代码组织和清晰的代码缩进对于提高代码可读性的重要性。文章还介绍了对象的概念,如何通过对象和集合来操作Excel中的数据,并通过简单的例子展示了对象的属性和方法如何让编程变得更加直观。

weixin_30820933的博客 790

WAVE格式

一.wave格式概述 Wave文件格式是用于多媒体文件存储的Microsoft RIFF(Resource Interchange FileFormat)的一个子集。每一个RIFF文件以一个文件头开始,后面是一系列数据块。Wave文件通常是包含“WAVE”块的RIFF文件。而该“WAVE”块由两个子块组成,称为“fmt”块。“fmt”块用于确定数据格式,并且“data”块包含实际的样本数据,

yejia1280的博客 4391

ESP32学习,驱动LED点阵屏,SD卡播放GIF动图

搬运就可以实现效果,如果有不足,请批评指正。下步该学一下如何文章上视频了,老是截图不方便展示效果。

u011625956的博客 1868

信捷 XDH Ethercat 正负极限配置详解与实战技巧

本文详细解析了信捷XDH系列PLC通过EtherCAT总线配置伺服电机正负硬极限的完整流程与实战技巧。内容涵盖硬件开关选型安装、EtherCAT IO信号映射、软件参数设置(包括关键的极性配置)、调试验证方法,以及硬极限与软极限的协同策略。重点阐述了如何避免常见配置错误,确保运动控制系统的最后一道物理安全防线可靠有效,为工程师提供从理论到实践的全面指导。

wdx012345的博客 603

手把手教你用支付宝密钥工具生成RSA2密钥对(含Windows/Mac操作截图)

本文详细介绍了如何使用支付宝密钥工具生成RSA2密钥对,包括Windows和Mac平台的操作步骤与截图。从工具下载、安装到密钥生成、配置支付宝平台,再到开发环境集成实战,手把手教你完成支付宝支付接口对接。特别强调密钥安全管理和最佳实践,帮助开发者避免常见安全隐患。

mongodb5scout的博客 260

Oracle 查看 rman 备份情况 SQL 语句

每天一个 DBA 小知识,助你更进一步!

LuciferLiu_DBA 3122

【数据集7】全球人类住区层GHSL数据详解

全球人类住区层GHSL数据详解

WW、forever的博客 2255

基于FPGA的万兆以太网学习(1)

万兆(10G) 以太网测速视频:SFP+屏蔽笼可以插入千兆或万兆光模块。SFP+信号定义与 SFP 一致。

baidu_34971492的博客 2250

22、常见加密哈希算法及安全机制解析

本文详细解析了多种常见加密哈希算法,包括SHA系列、RIPEMD、Tiger、HAVAL、Whirlpool等,涵盖其工作原理、安全性与性能对比。同时探讨了哈希攻击方式如预映像攻击和彩虹表,并介绍了盐、MAC、HMAC等防御机制。结合密码存储、消息完整性验证及区块链应用案例,分析了不同场景下的算法选择建议,并展望了哈希算法在创新、融合与标准化方面的未来发展趋势。

seed的博客 393

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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: 14、模糊技术与二维离散傅里叶变换在图像处理中的应用
下一篇: 29、神经离子电流与线性化:探索神经系统的奥秘
python9snake
博客等级 码龄1天 0粉丝 1724原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值