- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的宏中有这一行(Mac 上的 Excel 2011 VBA):
nWeekDaysBetween = (Application.WorksheetFunction.NetworkDays.INTL(pDate, aDate, 7) - 1)
当我运行宏时,它会突出显示 NetworkDays
并给出:
Compile error: Argument not optional.
该公式在直接输入单元格时有效,因此它可能确实存在。似乎它没有将 .INTL
识别为 NetworkDays
函数的一部分。
有什么想法吗?
以下是完整的代码供引用:
Sub BHSecondsBetween()
Dim includeWeekends As Integer: includeWeekends = 0
Dim weekendType As Integer: weekendType = 7
Dim openHour As Integer: openHour = 5
Dim closeHour As Integer: closeHour = 24
'weekendType options: (days of week to include as weekend days)
'1 Saturday and Sunday
'2 Sunday and Monday
'3 Monday and Tuesday
'4 Tuesday and Wednesday
'5 Wednesday and Thursday
'6 Thursday and Friday
'7 Friday and Saturday
'11 Sunday
'12 Monday
'13 Tuesday
'14 Wednesday
'15 Thursday
'16 Friday
'17 Saturday
' Remove rows without responses
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Replace What:="", Replacement:="ThisIsADummyStringForMacro", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="ThisIsADummyStringForMacro", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Columns("Q").SpecialCells(xlBlanks).EntireRow.Delete
Columns("M:M").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Dim NumRows As Integer
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
'Debug.Print "The value of variable NumRows is: " & NumRows
Dim pDate As Date
Dim aDate As Date
Dim nWeekDaysBetween As Integer
Dim answer As Integer
Dim pDiff As Long
Dim aDiff As Long
Dim pEndOfDay As Date
Dim aStartOfDay As Date
Dim endCell As String
For i = 2 To NumRows
On Error Resume Next
'Debug.Print "The value of variable i is: " & i
pDate = Worksheets("Sheet1").Cells(i, "F").Value
'Debug.Print "The value of variable pDate is: " & pDate
aDate = Worksheets("Sheet1").Cells(i, "T").Value
'Debug.Print "The value of variable aDate is: " & aDate
If includeWeekends = 1 Then
nWeekDaysBetween = DateDiff("d", pDate, aDate)
Else:
nWeekDaysBetween = (Application.WorksheetFunction.NetworkDays_INTL(pDate, aDate, 7) - 1)
End If
'Debug.Print "The value of variable nWeekDaysBetween is: " & nWeekDaysBetween
If nWeekDaysBetween < 0 Then
answer = 0
ElseIf nWeekDaysBetween = 0 Then
answer = DateDiff("s", pDate, aDate)
Else:
If (Hour(pDate) >= closeHour) Then
pDiff = 0
ElseIf (closeHour = 24) Or (closeHour = 0) Then
pEndOfDay = DateSerial(Year(pDate), Month(pDate), Day(pDate)) + TimeSerial(23, 59, 59)
pDiff = DateDiff("s", pDate, pEndOfDay)
Else:
pEndOfDay = DateSerial(Year(pDate), Month(pDate), Day(pDate)) + TimeSerial(closeHour, 0, 0)
pDiff = DateDiff("s", pDate, pEndOfDay)
End If
aStartOfDay = DateSerial(Year(aDate), Month(aDate), Day(aDate)) + TimeSerial(openHour, 0, 0)
If (Hour(aDate) < openHour) Then
aDiff = 0
Else:
aDiff = DateDiff("s", aStartOfDay, aDate)
End If
answer = pDiff + (60 * (closeHour - openHour)) * (nWeekDaysBetween - 1) + aDiff
End If
'Debug.Print "The value of variable answer is: " & answer
endCell = "M" & i
'Dim endContent As String: endContent = hours & ":" & minutes
Range(endCell).Value = answer
Next i
End Sub
最佳答案
您需要在 VBA 中使用 _
而不是 编写函数。
nWeekDaysBetween = (Application.WorksheetFunction.NetworkDays_Intl(pDate, aDate, 7) - 1)
使用内置的智能感知对于准确了解如何编写属性、方法等始终很有用。
关于excel - NETWORKDAYS.INTL() 函数在 VBA 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834350/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!