热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

通过VBA调试进入其他功能?

当我有一个包含自定义函数的VBA代码工作簿时,我注意到调试器会随机进入函数中间代码

当我有一个包含自定义函数的VBA代码工作簿时,我注意到调试器会随机进入函数中间代码。当我在.xlam文件中具有UDF以及在本地宏中具有自定义函数时,都会发生这种情况。如果它仅循环执行一次函数,但似乎无限循环,这将不是问题,这使得调试变得不可能。是否还有其他人有此问题,或者知道如何解决?

即这是今天给我的一个问题:

Sub checkdailytotal()
Dim i As Long,j As Long,k As Long,m As Long,n As Long
Dim filepath As String,filedate As String,filename As String,filename2 As String,filename3 As String,filetoopen As String
Dim totalunit As Double
Dim checkcount As Range
Dim wb As Workbook
Dim ws As Worksheet
Dim rg As Range,rg2 As Range,reg As Range,unitcol As Range,daterow As Range
Dim regcheck As Range,regfind As Range
Dim regnum As String,nofile As String,nofind As String,nomatch As String,totalmatch As String
Dim sharec As Double,sharediff As Double,totalshare As Double
Dim check As Range
Application.DisplayAlerts = False
Application.ScreenUpdating = False
filepath = "C:\username\filepath\"
On Error Resume Next
With Sheet3
Set checkcount = .Range("B2")
.Range("A3:E50").Clear 'This is where the function got called
End With
With Sheet2
i = WorksheetFunction.Count(.Range("A:A"))
Set reg = .Range("A2",.Cells(2,.Range("A2").End(xlToRight).Column))
Set unitcol = .Range("C2",.Cells(.Range("C2").End(xlDown).Row,"C"))
For j = 1 To i 'change this to i,just testing
Set daterow = .Range("A2").Offset(j,0)
checkcount.Offset(j,-1).Value = j
filedate = Format(.Range("A2").Offset(j,0).Value,"YYYYMMDD")
filename = filepath & "XYZ File name" & filedate & ".xlsx"
filename2 = filepath & "XYZ file name" & Format(.Range("A2").Offset(j,"DD.MM.YYYY") & ".xlsx"
filename3 = filepath & filedate & ".xlsx"
If Len(Dir(filename)) = 0 Then
If Len(Dir(filename2)) = 0 Then
If Len(Dir(filename3)) = 0 Then
nofile = "No File"
Else
filetoopen = filename3
End If
Else
filetoopen = filename2
End If
Else
filetoopen = filename
End If
Set wb = Workbooks.Open(filetoopen,Password:="password")
Set ws = wb.Worksheets(1)
With ws
nofind = ""
nomatch = ""
Set regcheck = .Range("H2")
n = .Range("A2").End(xlDown).Row - 2
For k = 1 To n
regnum = regcheck.Offset(k,0).Value
Set regfind = reg.Find(regnum,LookIn:=xlValues,lookat:=xlWhole)
If regfind Is Nothing Then
nofind = nofind & " " & regfind
Else
sharec = regfind.Offset(j,0).Value 'find the sharecount in monthly file
sharediff = regcheck.Offset(k,4).Value - sharec
If Abs(Round(sharediff,1)) > 0 Then
nomatch = nomatch & " " & regfind & " " & sharediff
End If
End If
Next k
wb.Close False
totalshare = regcheck.Offset(j + 1,4).Value
totalmatch = Abs(Round(totalshare - unitcol.Value,1))
Call totalcheck(daterow.Value,nofile,totalmatch,nofind,nomatch)
nofile = ""
End With
Next j
End With
MsgBox "Check complete"
Application.Goto Sheet3.Range("A1")
End Sub
Sub totalcheck(datech As Double,nofilepath As String,totalshare As String,regfind As String,regmatch As String)
Dim check As Range
Dim m As Long
With Sheet3
Set check = .Range("B2")
m = WorksheetFunction.Count(.Range("A:A"))
Set check = check.Offset(m,0)
With check
With .Offset(0,0)
.Value = datech
.NumberFormat = "m/d/yyyy"
End With
.Offset(0,1).Value = nofilepath
.Offset(0,2).Value = totalshare
.Offset(0,3).Value = regfind
.Offset(0,4).Value = regmatch
End With
End With
End Sub
Function tplus1(todaydt As Date)
Dim holidays As Range
Dim wk As Long,wk2 As Long,wk3 As Long,i As Long,j As Long
Dim t1 As Date
wk = WorksheetFunction.Weekday(todaydt,2) 'mon=1,sun=7
If wk > 5 Then
tplus1 = "Weekend"
Exit Function
End If
If wk <5 Then 'mon-thurs
t1 = todaydt + 1
Else 'friday
t1 = todaydt + 3
End If
With Sheet4
Set holidays = .Range("A2",.Cells(.Range("A2").End(xlDown).Row,"A"))
End With
i = WorksheetFunction.CountIf(holidays,t1)
wk2 = WorksheetFunction.Weekday(t1,sun=7
If i = 0 Then
tplus1 = t1
Exit Function
End If
If i > 0 Then
Do Until i = 0
If wk2 <5 Then
t1 = t1 + 1
i = WorksheetFunction.CountIf(holidays,t1)
ElseIf wk2 = 5 Then
t1 = t1 + 3
i = WorksheetFunction.CountIf(holidays,t1)
ElseIf wk2 = 6 Then
t1 = t1 + 2
i = WorksheetFunction.CountIf(holidays,t1)
ElseIf wk2 = 7 Then
t1 = t1 + 1
i = WorksheetFunction.CountIf(holidays,t1)
End If
wk2 = WorksheetFunction.Weekday(t1,2)
Loop
End If
tplus1 = t1
End Function





推荐阅读
  • 怎么在PHP项目中实现一个HTTP断点续传功能发布时间:2021-01-1916:26:06来源:亿速云阅读:96作者:Le ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 第四章高阶函数(参数传递、高阶函数、lambda表达式)(python进阶)的讲解和应用
    本文主要讲解了第四章高阶函数(参数传递、高阶函数、lambda表达式)的相关知识,包括函数参数传递机制和赋值机制、引用传递的概念和应用、默认参数的定义和使用等内容。同时介绍了高阶函数和lambda表达式的概念,并给出了一些实例代码进行演示。对于想要进一步提升python编程能力的读者来说,本文将是一个不错的学习资料。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • Ihaveaworkfolderdirectory.我有一个工作文件夹目录。holderDir.glob(*)>holder[ProjectOne, ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • 巧用arguments在Javascript的函数中有个名为arguments的类数组对象。它看起来是那么的诡异而且名不经传,但众多的Javascript库都使用着它强大的功能。所 ... [详细]
  • ***Createdbyjiachenpanon161118.**合法uri*exportfunctionvalidateURL(textval){consturlregex^( ... [详细]
  • SoIhavealoopthatrunsperfectforeventsandonlyshowsfutureposts.TheissueisthatIwould ... [详细]
author-avatar
Gemini_2
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有