工作簿,保存,关闭,重新打开(带TimeValue),重复 [英] Workbook, Save, Close, Re-Open (w/ TimeValue),Repeat

查看:73
本文介绍了工作簿,保存,关闭,重新打开(带TimeValue),重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该宏通过分配给"CloseMe"的按钮运行.它曾经可以满足我的需求,但现在不再运行(因为我尝试在另一个工作簿中使用此代码但没有成功).现在保存,关闭,等待10秒重新打开,然后立即关闭.

The macro runs with a button assigned to "CloseMe". It used to run for my needs but doesn't anymore (as I tried using this code in another workbook without success). Now it saves, closes, waits 10sec to reopen, but then closes right away.

Sub CloseMe()
Application.OnTime Now + TimeValue("00:00:10"), "OpenMe"
ThisWorkbook.Close True
End Sub

Sub OpenMe()
Application.OnTime Now + TimeValue("00:10:00"), "OpenMe"
ThisWorkbook.Close True
End Sub

我需要代码来保存,关闭,等待10秒重新打开,保持打开状态10分钟(以收集实时数据),然后重复此过程(直到我手动中断以停止操作).谢谢

I need the code to save, close, wait 10sec to reopen, stay open for 10min (to collect real time data), and then repeat this process (until I interrupt it manually to stop). Thanks

推荐答案

该代码执行了您要执行的操作: CloseMe 从现在开始将 OpenMe 安排10秒钟,然后关闭工作簿,然后关闭b.Excel重新打开工作簿并调用 OpenMe ,该计划从现在开始将自身安排10分钟,然后立即继续关闭工作簿,最后Excel在10分钟后恢复,成一个循环.

The code does what you are asking it to do: a. CloseMe schedules OpenMe for 10 seconds from now and closes the workbook, then b. Excel re-opens the workbook and invokes OpenMe, which schedules itself for 10 minutes from now, then immediately proceeds to close the workbook, and finally Excel resumes at b 10 minutes later, in a loop.

我的理解是,您的代码必须在 OpenMe CloseMe 中执行某些操作,因此您不想仅安排呼叫并关闭工作簿.此外,要循环,一个子需要安排另一个子.概括地说,您可以遵循以下原则:

My understanding is that your code has to perform something either in OpenMe or CloseMe, so you do not want to just schedule a call and close the workbook. Additionally, to cycle, one sub needs to schedule the other. In broad terms, you could go along those lines:

Sub CloseMe()
    'Here, do whatever (if anything) must be done just before saving the workbook.
    '...

    'Schedule the OpenMe execution in 10 seconds.
    'I don't understand why you need to close the workbook, but that's not the question.
    Application.OnTime Now + TimeValue("00:00:10"), "OpenMe"
    ThisWorkbook.Close True
End Sub

Sub OpenMe()
    'Here, do whatever (if anything) must be done just as the workbook opens.
    '...

    'Schedule the CloseMe execution in 10 minutes.
    Application.OnTime Now + TimeValue("00:10:00"), "CloseMe"
End Sub

这篇关于工作簿,保存,关闭,重新打开(带TimeValue),重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆