无法运行宏 [英] Cannot run the macro

查看:392
本文介绍了无法运行宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的宏中遇到问题

  Sub RefreshAction()
Range(b7) 。选择
Application.RunRefreshCurrentSelection
Application.OnTime(Now()+ TimeValue(00:00:05)),thisworkbook.Action
End Sub

第一次运行宏时,单元格刷新,但是在

$后立即收到错误消息b
$ b

消息:无法运行宏C\Desktop\XYZ.xlsm'!thisworkbook.Action'。该宏可能在此工作簿中可用,或者所有宏可能被禁用。 / p>

我已经通过了信任中心 - 信任中心设置 - >宏设置 - >启用所有宏,并且没有起作用。



还点击对VBA项目对象模型的信任访问框。

解决方案

绝对参考更多细节: CPearson OnTime



第一个问题,您需要将您输入的时间存储在 OnTime 方法能够阻止它。 (这里我宣布了一个公共TimeToRun As日期)



第二点要使用 OnTime 方法,您需要在定时过程结束时重置计时器(这里 RefreshAllStaticData )。



所以你的整个代码应该如下所示:

  Public TimeToRun As Date',以便TimeToRun可以用于功能

Sub RefreshAction()
范围(b7)。选择
Application.RunRefreshCurrentSelection
DoEvents
'Store TimeToRun中的下一个执行日期
TimeToRun = Now()+ TimeValue(00:00:05)
'启动下一个OnTime
Application.OnTime TimeToRun,RefreshAllStaticData
End Sub


Sub RefreshAllStaticData()

' - ++ - 将您的代码放在这里,因为它现在是++ -

'----调用RefreshAction将OnTime方法
'---------重新设置为另外5秒,并保持循环
RefreshAction

End Sub


Sub Kill_OnTime()
'启动此功能以停止OnTime方法
应用程序。 OnTime _
earliesttime:= TimeToRun,_
procedure:=RefreshAllStaticData,_
schedule:= False
End Sub
/ pre>

I have encountered a problem in the macro below

Sub RefreshAction()
    Range("b7").Select
    Application.Run "RefreshCurrentSelection"
    Application.OnTime (Now() + TimeValue("00:00:05")), "thisworkbook.Action"
End Sub

The cell refreshes when I run the macro the first time but I get the error message immediately after

Message: Cannot run the macro "C\Desktop\XYZ.xlsm'!thisworkbook.Action'. The macro may not be available in this workbook or all macros may be disabled.

I have already gone through "Trust Center->Trust Center Settings->Macro Settings->Enable all macros and it didn't work.

The "Trust access to VBA project object model" box is also clicked.

解决方案

See the absolute reference for more details : CPearson OnTime

First issue, you need to store the time that you'll input in your OnTime method to be able to stop it. (Here I declared a Public TimeToRun As Date)

Second Point To use the OnTime method continuously, you need to reset the timer at the end of your timed procedure (here RefreshAllStaticData).

So your whole code should look like this :

Public TimeToRun As Date 'so that TimeToRun can be used in both the functions

Sub RefreshAction()
    Range("b7").Select
    Application.Run "RefreshCurrentSelection"
    DoEvents
    'Store the next date of execution in TimeToRun
    TimeToRun = Now() + TimeValue("00:00:05")
    'Launch the next OnTime
    Application.OnTime TimeToRun, "RefreshAllStaticData"
End Sub


Sub RefreshAllStaticData()

'--++-- Place your code here, as it is now --++--

'----Call RefreshAction to reset the OnTime method
'---------to another 5 seconds and keep "looping"
RefreshAction

End Sub


Sub Kill_OnTime()
'Launch this to stop the OnTime method
Application.OnTime _
    earliesttime:=TimeToRun, _
    procedure:="RefreshAllStaticData", _
    schedule:=False
End Sub

这篇关于无法运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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