我需要创建一个在启动时在Outlook中运行的VBA脚本,然后再以两分钟的间隔创建。这是:
Private Sub Application_Startup()
Call doThis
End Sub
Private Sub checkEmail(Item As Outlook.MailItem)
'lots of code here
End Sub
Sub doThis()
Dim myInbox As Outlook.Folder
Dim ToPrint As Outlook.Folder
Dim myNameSpace As NameSpace
Dim objItems As Outlook.Items
Dim objItem As Outlook.MailItem
Set myNameSpace = Application.GetNamespace("MAPI")
Set ToPrint = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("ToPrint")
Set objItems = ToPrint.Items
For Each objItem In objItems
Call checkEmail(objItem)
Next
Application.Ontime Now + TimeValue("00:02:00"), "doThis"
Set myInbox = Nothing
Set ToPrint = Nothing
Set myNameSpace = Nothing
Set objItem = Nothing
Set objItems = Nothing
End Sub
所以代码运行得很顺利,除非我到达这一行:
Application.Ontime Now + TimeValue("00:02:00"), "doThis"
此时,我收到运行时错误438:“对象不支持此属性或方法。”
有人有想法吗?我是VBA的新手,但在过去的几周里我学到了很多东西。我很感激你的帮助。
答案 0 :(得分:1)
Outlook不支持<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script>
var sources = ["/path/to/audio/src/1"
, "/path/to/audio/src/2"];
var src = sources.slice(0); // copy original array
function getAudio(url) {
return new Promise(function(resolve, reject) {
var audioCtx = new(window.AudioContext || window.webkitAudioContext)();
var source = audioCtx.createBufferSource();
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.onload = function() {
var audioData = request.response;
audioCtx.decodeAudioData(audioData).then(function(decodedData) {
source.buffer = decodedData;
source.connect(audioCtx.destination);
console.log(source, decodedData);
// do stuff when current audio has ended
source.onended = function() {
console.log("onended:", url);
if (src.length)
resolve(src)
else resolve("complete")
}
source.start(0);
});
}
request.send();
})
}
var audio = (function tracks(s) {
return getAudio(s.shift())
.then(function(data) {
if (Array.isArray(data) && data.length) return tracks(data)
else return data
})
}(src));
// do stuff when all `src` have been requested, played, ended
audio.then(function(msg) {
console.log(msg)
})
</script>
</head>
<body>
</body>
</html>
或Application.Run
方法。
但是你可以使用支持它的Object模型的OnTime方法,比如Excel。也就是说,您可以从Excel自动化Outlook,但根据您希望在Outlook中实现的目标,Outlook对象模型防护可能会阻止您。