问题描述
我试图使msgbox出现在B4:B160范围内的单元格值在30秒或1分钟等时间内未发生变化时.因此,将出现类似您扫描过吗?"之类的内容.并且只会在30秒内没有在该单元格中输入数据的情况下显示,但也会在6分钟或输入数据后关闭.如果我可以在代码中调整这些时间,那就太好了.
I am trying to make a msgbox appear when a cell value in range B4:B160 hasn't changed in 30secs or 1min etc.So what will appear is something like 'Have you scanned?' and will only appear if they haven't entered data in that cell in 30secs but will also close itself after 6mins or when they do enter data. It would be great if i can adjust these times in the code.
我的电子表格用于条形码扫描,当他们输入错误的数据时,当前已经在运行用户表单.我可以添加另一个已计时的用户表单吗?还是一次只能送一个人?
My spreadsheet is used for barcode scanning and is currently already running a userform when they enter the wrong data. Can I add another userform which is timed? or can I only have one going at a time?
道歉很多问题,但是我一直坚持让它工作一个星期,并记得Stack Overflow的这个团队是问问最好的地方.
Apologies a lot of questions but Ive been stuck on getting this to work for a week now and remembered this team at Stack Overflow is the best place to ask.
我有此代码,当前正在工作,但计时器正在为每个单元格启动,并与每次更改一样多次弹出.仅当一个单元发生更改时,如何才能弹出它?当我输入超过10秒时,持续时间也非常不一致.我需要将它用于范围B4-B168而不是范围G,因为这是我正在运行的另一项检查.
I have this code and is currently working but the timer is starting for each cell and pops up as many times as each of the changes. How do I get it to pop up only if one cell has changed? ALSO the duration is very inconsistent when I type in more than 10secs. I need this to be working for range B4-B168 not G Range as that is for another check that im running.
私人子Worksheet_change(按目标的ByVal目标)将myCell调整为范围
Private Sub Worksheet_change(ByVal Target As Range)Dim myCell As Range
For Each myCell In Range("G4:G168")
If (Not IsEmpty(myCell)) And myCell.Value <> 17521 And myCell.Value <> "" Then
DisplayUserForm1
Exit Sub
End If
Next myCell
startTimer
End Sub
Option Explicit
'Time before msgbox closes
Const PopupDurationSecs As Integer = 30
Sub startTimer()
'Time of msgbox before it opens
Application.OnTime Now + TimeValue("00:02:30"), "myShellMessageBox"
End Sub
Sub myShellMessageBox()
Dim Result As Integer
'.popup("strText",nSecondstowait,"strTitle",[nType])
Result = CreateObject("WScript.Shell").Popup("Have you scanned?",
PopupDurationSecs, "Barcode Scan", 0 + 32)
'MsgBox Result
If Result = 1 Then
Exit Sub
End If
End Sub
推荐答案
Duration = 30
TimeStart = Mid(15,2Now())
TimeEnd = Mid(15,2Now())
If TimeEnd-TimeStart >= Durarion Then
VBA确实从上到下运行,这意味着通过在代码中的不同位置获取Now()可以在时间上有所不同.这应该是技巧.
VBA does run things from top to bottom, meaning that you’ll get a difference in time by getting Now() at different places in the code. This should to the trick.
这篇关于当单元格值在30秒或1分钟等时间内未更改时,如何显示msgbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!