VBA Excel 自定义函数不能调用成功的问题的解决方法

python win32com Dispatch, DispatchEx 无法打开(启动)excel pywintypes.com_error: (-2146959355, ‘服务器运行失败‘ 最近换了个硬盘,重装电脑后,想用python打开excel,发现完全没反应,弹出以下错误信息: asctime: Sun, 02 May 2021 12:48:36 bug_line: line:509 level: ERROR message: ERROR:(-2146959355, '服务器运行失败', None, None) Traceback (most recent call last): File "D:\Python\Py 阅读详情
AI摘要

本文深入探讨了VBAExcel自定义函数无法调用的原因及解决策略,包括函数定义错误、作用域限制、命名冲突等问题,并通过具体实例说明如何正确创建和使用自定义函数。

VBA Excel 自定义函数不能调用成功的问题的解决方法

问题以及解决方案的列举(持续更新中)

自定义函数是自动化各种Excel重复操作的重要函数,我们可以用它实现各种自己的奇葩需求。但是当我退出VBA代码编辑界面调用时,却发现Excel找不到我定义的函数,那么可能有以下很多种原因可以导致上述的问题:

  1. 在VBA中误写定义为Sub 子程序,而不是 Function 函数,导致Excel不能识别。
  2. 在当前Sheet或者工作簿下 写VBA,而不是创建一个新的模块编写VBA。(本人是这个错误)
  3. 在其他的工作簿下 写VBA,导致在当前excel文件下不识别。
  4. 函数名和Excel自带函数名重复导致冲突。
  5. 网传Office破解版不能调用自定义函数,但是我使用的就是破解版,也可以识别。因此仅做参考。
Function Merge_single(x As Range, y As Range)                  'This function is to filter some infomations indicated and put them together
    Dim wb As Object
    Dim st As Object
    Dim xx, yy As Range
    Dim xstr, ystr As String
    Dim rr As Integer
    If x.rows.Count <> y.rows.Count Then
        MsgBox "The variables you enter don't have the same column"
    End If
    Call del_text(x)
    Call del_text(y)
    ystr = Cells(y.Row, y.Column).Value
    xstr = filter(x)
    Merge_single = ystr & xstr
    xstr = ""
    ystr = ""
End Function

当解决问题后,在Excel界面可以像正常函数一样使用你的自定义函数。如下图所示。在这里插入图片描述

vba自定义函数,设置加载宏,建立自己的excel函数库,代码库 今天的文章真的厉害了,我们都知道excel有很多强大的函数。比如sum,count,if非常的好用。那我们能不能自己定义函数来使用呢! 当然可以,下面我们就来定义函数并且使用它。 案例一: 提取身份证中的生日,如下图: 用excel自带的函数也可以实现 方法1.MID(A1,7,4)&"/"&MID(A1,11,2)&"/"&MID(A1,13,2) 方法2.TEXT(MID(A1,7,8),"0000/00/00") 但是方法1,太长了,比较 阅读详情

相关推荐

【 VBA 编程】告别公式嵌套!用VBA自定义函数让Excel效率翻倍

本期分享编程知识:利用VBA创建自定义函数,将复杂的Excel公式封装为简洁的函数,解决晦涩难懂的Excel公式嵌套问题

wei1019的专栏 1252

vba excel 2007 自定义函数 不能运行 #name 解决办法

http://zhidao.baidu.com/question/205789958.html

java journey 5011

VBA中调用XLA

XLA,在office97-2003中是excel加载宏文件,其功能类似于dll,认为是定义好的库函数,可供人调用。 但是xla文件如何加载和使用成了问题。查阅了很多资料,最后在 http://club.officefans.net/cdb/viewthread.php?tid=81156 这里找到了正确答案,向crdotlin 表示感谢! (1)编写xla 将以下代码写到xla.xla中:

Waleking的专栏 9209

EXCEL自定义函数无法运行的原因:可以在VBA里运行的函数,在EXCEL用自定义函数为什么报错?

但是问题来了,为啥这样设置自定义函数不行呢? Function qiuhe1(a, b) qiuhe1 = a + b End Function Function qiuhe111() '自定义函数正常 qiuhe111 = 100 End Function Function qiuhe112() '这个弄成自定义函数就返回错误值 qiuhe112 = 100 Cells(3, 6) = "自定义函数qiuhe112=" ....

奔跑的犀牛先生 7555

Excel VBA函数与方法的全面指南

在Excel中进行自动化工作和数据分析时,VBA(Visual Basic for Applications)函数是不可或缺的工具。这些函数不仅能够简化复杂的任务,还能够大幅度提高工作流程的效率。本章将对Excel VBA中的函数进行概述,帮助读者快速了解VBA函数的基本概念及其在实际工作中的应用。VBA是Excel内置的编程语言,通过VBA函数可以实现对Excel的深度定制。

weixin_33597080的博客 1013

VBA-自定义函数大全

VBA-自定义函数大全

VBA中如何调用自定义函数

在VBA中我要把B列中所有的非空单元格的值都判断一遍,如果大于60就在其旁边的单元格写入"及格",反之就写入不及格。由于B列的非空单元格数量无法确定,所以我们就要定义一个自定义的函数来获取B列中最后一个非空单元格的值,然后再进行遍历循环。在VBA中,End(xlUp)是一个用于定位单元格的方法,它可以用于查找某一列或行最后一个非空单元格的位置。

henanlion的博客 4048

vba像自定义函数一样调用易语言DLL并返回文本

vba像自定义函数一样传递文本调用易语言DLL并返回文本

VBA之使用自定义函数

如何在vba中使用自定义的函数呢? 首先在模块里定义好函数,然后注意要往里面传参 然后在excel单元格里调用该函数 1.需求1,判断性别 代码如下 Function zmj(x) zmj = (x / 6.03) - x * 0.03 End Function Function xb(x As String) If x = "男" Then xb = "先生" ElseIf x =...

amamiyayouko的博客 1万+

OpenCV学习笔记(25)基于MFC和OpenCV的摄像机定标与立体匹配测试程序(20140505更新)

最近整理了一下这两年一直在用的摄像机定标与立体匹配测试程序,将代码进行了重构,界面也做了调整,分享出来方便有需要的朋友使用。当然我的编程能力有限,程序可能还有各种bug,请大家多多包涵。相关问题欢迎留言或email联系讨论,谢谢! ==================================================================================源码

晨宇思远 5万+

SpringBoot 中 @RequestMapping 及衍生注解的全面解析与实践

本文全面解析Spring Boot中@RequestMapping及其衍生注解的使用,涵盖核心功能、HTTP方法特定注解(@GetMapping/@PostMapping等)、属性详解(路径/参数/头信息等)以及路径变量处理。文章详细介绍了注解的组合使用、继承特性、版本控制策略等高级应用,并针对405/404等常见错误提供解决方案。通过学习这些注解的规范用法,开发者能够构建符合RESTful风格的API接口,提升代码可读性和可维护性。建议优先使用HTTP方法特定注解,合理规划URL结构,并注意避免路径冲突。

Java&AI小吕布的博客 2038

VBA学习笔记:在vba中使用内置函数的两种方式

Excel中有很多内置函数,在VBA中想要使用这些内置函数,该怎么使用呢?

l_q_l的专栏 1457

KF-gins输出结果绘图

KF-gins输出结果绘图

m0_51977577的博客 1109

VBA中调用excel的函数

点击打开链接

qq_25245887的博客 4万+

关于42步进电机驱动——基于STM32 HAL库实现

我找了好多资料,好多关于42步进电机的都是文档,这么文档都需要积分,需要积分就算了内容还非常差,浪费时间和电脑的内存。关于大部分是基于Arduino和51去驱动的 42步进电机驱动硬件如下: 首先你要了解步进电机的驱动原理,我也不啰嗦了,请看这边博客: 二相四线,四相五线,四相六线步进电机接线及驱动方法 , 看完这篇你就知道驱动和接线的原理了。 起初我也为如何接线烦恼,因为有些博客在讲述这些问题的时候没有讲的很透彻。 方法如下: ①用万用表调到欧姆档,用其中一个表笔搭在一个引脚上,依次测其它.

Jodan132的博客 1万+

手把手教你用Python模拟侧信道攻击:从电磁辐射到数据窃取(附防御代码)

本文详细介绍了如何使用Python模拟侧信道攻击,从电磁辐射信号采集到数据窃取的全过程,并提供了实用的防御代码。通过实战案例,帮助安全研究员和开发者理解侧信道攻击原理,掌握信号处理与图像重建技术,同时学习有效的噪声干扰和电磁屏蔽防御措施。

weixin_28716443的博客 164

【Excel VBA】在VBA中调用函数

在VBA代码中直接调用计算数据 EXCEL的表函数也可以直接在VBA中直接调用执行,具体调用格式如下: 调用方法1:变量对象= Application.WorksheetFunction.表函数(表函数参数) 实例:Range("d8") = Application.WorksheetFunction.CountIf(Range("A1:A10"), "B")...

Cecilia_W422的博客 2万+

河洛理数【陈抟】先天命卦大运

首先我们把前文提及的天干和地支进行上下划分,那么每一年的年份都是使用一天干和一地支进行组合,即如上的甲子、癸亥,那么下一年就是天干和地支都进行顺延一位进行组合,如甲子年下一年就是乙丑年,但是由于天干是十个、地支有十二个,所以要遍历一遍的话,就正好是 60 年。1924 年 ~ 1983 年(中元) 1984 年 ~ 2043 年(下元) 2044 年 ~ 2103 年(上元)2、找到卦中第一个(从下往上,也就是初爻、二到五爻、上爻)对应时辰的阴阳爻。5、也就是所属的元堂爻。

Daniel专栏 2079

【原创】VBA学习笔记(18) VBA的自定义函数 / 过程,到底能不能改变EXCEL单元格内容?

一 自定义函数 1.1 什么是EXCEL 的自定义函数 VBA里用户自己写了一些函数,这些非 EXCEL 和 VBA 内置的函数,也可以在EXCEL直接使用 VBA的函数在 EXCEL里如何使用? 单元格里输入 = 自定义函数名 即可 1.2 明确概念: 函数错误 Vs 函数返回值错误 函数错误:是 语法错误,允许错误,逻辑错误等等 函数返回值错误:是 函数调用后,返回值报错了...

奔跑的犀牛先生 5818

置顶必读(1) |《YOLOv11实战:从入门到深度优化》专栏导读,带你一文了解本专栏!

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏,该专栏专注于分享我在YOLOv8目标检测模型中的实战经验,涵盖从入门基础到深度优化的全方位解决方案。无论你是计算机视觉的新手,还是具有多年深度学习经验的专家,本专栏都将为你提供高效、可复现的技术方案,助你掌握YOLOv8的核心技术,提升目标检测性能,突破瓶颈,优化模型,并加速项目开发🚀!

**My Coding Family** 12万+

Unity-TextMeshPro如何扩展材质实现字体Face+Outline流光效果

前言 TexeMeshPro 是Unity的一个Text文本插件,实现了比UGUI的Text,更好看的效果,跟高效的性能,所以深受大家的喜欢,但是再好的插件,也不是万能的,比如我们的策划有个新需求,要我们的VIP的名字比普通玩家有更好看的效果,例如:字体流光,外发光颜色扰动,字体贴图等等。那我们就需要去扩展TextMeshPRo的shader功能了。如下图所示 本文,我就带大家一起来扩展一下:如何扩展TextMeshProUGUI TextMesh原始面板 扩展功能后的面板 扩展TextMeshPro

TxNet 9692

excel vba 调用webbrowser_VBA 公式与函数

一, 在单元格中输入公式的3种方法:1) 用VBA在单元格中输入普通公式Sub formula_1() Range("d2") = ("=B2 * C2") End Sub运行程序后,在D2的单元格内显示的是公式 =B2 * C2 ,并非程序返回值.下文(二)中会介绍另外一种直接返回值的方式想要通过程序一次计算完所有D列金额,只要运行上一篇文章循环语句...

weixin_39545017的博客 1535

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

调用vba_怎么在VBA中引用或者调用函数公式?

我的目标:让中国的大学生走出校门的那一刻就已经具备这些Office技能,让职场人士能高效使用Office为其服务。支持鹏哥,也为自己加油!在日常工作中,Excel里面很多函数我们都用过,比如求和函数sum,sumif,计数函数count,countif。同样在VBA里面也有一些函数,我们称之为VBA函数,相对于VBA函数,我们经常在工作里面使用的函数称之为工作表函数。在写代码时,我们可以...

weixin_42519725的博客 1万+

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

VBA中调用Excel函数

j= excel.Application.WorksheetFunction.vlookup() j= excel.Application.WorksheetFunction.xxxx example:

Alvin_CC的博客 3935

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

调用vba_Excel VBA|在VBA中调用Windows API库中函数

任何一个稍复杂的程序都不是从0开始的,都是从库(函数库或类库)搭建起来的。在Excel VBA中,你可以调用工作表的函数、VBA函数、可以引用用户自己定义的函数或过程。除此以外,还可以调用Windows API库的函数。Windows API是Windows编程人员可以使用的一套函数。在VBA模块中引入某个库的函数后,便可直接调用这个Windows函数。引入Windows API库的某个函数需要在...

weixin_31998371的博客 3140

怎样通过python调用word或Excel中的vba函数

读取原始数据表。调用VBA函数对数据进行预处理。使用Python进行进一步的数据分析。输出最终报告至Word文档。

xiamu_CDA的博客 1952
上一篇: Django 静态资源管理问题解决 持续更新中
下一篇: VBA Excel 单元格内多行内容的文字处理方法
Volavion
博客等级 码龄9年 3788粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Volavion

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值