VBA Outlook/Excel Object model
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
While coding, i've noticed a quite funny thing which, unfortunately, I wasn't able to google. That's why raising it here -- maybe you can help me. Below code, copied from MSDocs works fine.
Sub MSCodeTest()
Dim oApp As Object 'added by me
Dim oNamespace As Namespace
Dim oFolder As Folder
Dim oSharingItem As SharingItem
On Error GoTo ErrRoutine
Set oApp = GetObject(, "Outlook.Application")'added by me
Set oNamespace = oApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oSharingItem = oNamespace.CreateSharingItem(oFolder)
oSharingItem.Display
EndRoutine:
On Error GoTo 0
Set oSharingItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.source
GoTo EndRoutine
End Sub
Whenever I'll change oNamespace from Namespace to Object type it returns error msg like this:
Error Description --> "The operation failed." ; Error Number -->-2147467259; Error Source --> Microsoft Outlook
I'm just wondering why this error occurs especially that all variables are an object type. To add one thing - I've tested it in MS Excel. Thanks.
vba excel outlook
$endgroup$
add a comment |
$begingroup$
While coding, i've noticed a quite funny thing which, unfortunately, I wasn't able to google. That's why raising it here -- maybe you can help me. Below code, copied from MSDocs works fine.
Sub MSCodeTest()
Dim oApp As Object 'added by me
Dim oNamespace As Namespace
Dim oFolder As Folder
Dim oSharingItem As SharingItem
On Error GoTo ErrRoutine
Set oApp = GetObject(, "Outlook.Application")'added by me
Set oNamespace = oApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oSharingItem = oNamespace.CreateSharingItem(oFolder)
oSharingItem.Display
EndRoutine:
On Error GoTo 0
Set oSharingItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.source
GoTo EndRoutine
End Sub
Whenever I'll change oNamespace from Namespace to Object type it returns error msg like this:
Error Description --> "The operation failed." ; Error Number -->-2147467259; Error Source --> Microsoft Outlook
I'm just wondering why this error occurs especially that all variables are an object type. To add one thing - I've tested it in MS Excel. Thanks.
vba excel outlook
$endgroup$
$begingroup$
What happens if you change its type toVariant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.
$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you usingCreateObjectinstead of justNewing up theOutlook.Applicationinstance?
$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
Are you sure it's theAs Objectthat's blowing up and not the fact that you're providing theOutlook.Applicationprogid into the 2nd argument rather than the first? Which line is throwing the error, specifically?
$endgroup$
– Mathieu Guindon
25 mins ago
add a comment |
$begingroup$
While coding, i've noticed a quite funny thing which, unfortunately, I wasn't able to google. That's why raising it here -- maybe you can help me. Below code, copied from MSDocs works fine.
Sub MSCodeTest()
Dim oApp As Object 'added by me
Dim oNamespace As Namespace
Dim oFolder As Folder
Dim oSharingItem As SharingItem
On Error GoTo ErrRoutine
Set oApp = GetObject(, "Outlook.Application")'added by me
Set oNamespace = oApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oSharingItem = oNamespace.CreateSharingItem(oFolder)
oSharingItem.Display
EndRoutine:
On Error GoTo 0
Set oSharingItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.source
GoTo EndRoutine
End Sub
Whenever I'll change oNamespace from Namespace to Object type it returns error msg like this:
Error Description --> "The operation failed." ; Error Number -->-2147467259; Error Source --> Microsoft Outlook
I'm just wondering why this error occurs especially that all variables are an object type. To add one thing - I've tested it in MS Excel. Thanks.
vba excel outlook
$endgroup$
While coding, i've noticed a quite funny thing which, unfortunately, I wasn't able to google. That's why raising it here -- maybe you can help me. Below code, copied from MSDocs works fine.
Sub MSCodeTest()
Dim oApp As Object 'added by me
Dim oNamespace As Namespace
Dim oFolder As Folder
Dim oSharingItem As SharingItem
On Error GoTo ErrRoutine
Set oApp = GetObject(, "Outlook.Application")'added by me
Set oNamespace = oApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oSharingItem = oNamespace.CreateSharingItem(oFolder)
oSharingItem.Display
EndRoutine:
On Error GoTo 0
Set oSharingItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.source
GoTo EndRoutine
End Sub
Whenever I'll change oNamespace from Namespace to Object type it returns error msg like this:
Error Description --> "The operation failed." ; Error Number -->-2147467259; Error Source --> Microsoft Outlook
I'm just wondering why this error occurs especially that all variables are an object type. To add one thing - I've tested it in MS Excel. Thanks.
vba excel outlook
vba excel outlook
asked 56 mins ago
SmolarSmolar
62
62
$begingroup$
What happens if you change its type toVariant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.
$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you usingCreateObjectinstead of justNewing up theOutlook.Applicationinstance?
$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
Are you sure it's theAs Objectthat's blowing up and not the fact that you're providing theOutlook.Applicationprogid into the 2nd argument rather than the first? Which line is throwing the error, specifically?
$endgroup$
– Mathieu Guindon
25 mins ago
add a comment |
$begingroup$
What happens if you change its type toVariant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.
$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you usingCreateObjectinstead of justNewing up theOutlook.Applicationinstance?
$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
Are you sure it's theAs Objectthat's blowing up and not the fact that you're providing theOutlook.Applicationprogid into the 2nd argument rather than the first? Which line is throwing the error, specifically?
$endgroup$
– Mathieu Guindon
25 mins ago
$begingroup$
What happens if you change its type to
Variant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
What happens if you change its type to
Variant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you using
CreateObject instead of just Newing up the Outlook.Application instance?$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you using
CreateObject instead of just Newing up the Outlook.Application instance?$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
Are you sure it's the
As Object that's blowing up and not the fact that you're providing the Outlook.Application progid into the 2nd argument rather than the first? Which line is throwing the error, specifically?$endgroup$
– Mathieu Guindon
25 mins ago
$begingroup$
Are you sure it's the
As Object that's blowing up and not the fact that you're providing the Outlook.Application progid into the 2nd argument rather than the first? Which line is throwing the error, specifically?$endgroup$
– Mathieu Guindon
25 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217548%2fvba-outlook-excel-object-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217548%2fvba-outlook-excel-object-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
What happens if you change its type to
Variant? That said, Code Review is all about improving your own working code - this question looks like it might be a better fit on Stack Overflow.$endgroup$
– Mathieu Guindon
32 mins ago
$begingroup$
Hi. This is a great question. For Stack Overflow. This is Code Review, and as such this is off topic here, since this stack is for improving working code and not fixing broken code.
$endgroup$
– FreeMan
32 mins ago
$begingroup$
If you're referencing the Outlook type library, then why are you using
CreateObjectinstead of justNewing up theOutlook.Applicationinstance?$endgroup$
– Mathieu Guindon
31 mins ago
$begingroup$
Are you sure it's the
As Objectthat's blowing up and not the fact that you're providing theOutlook.Applicationprogid into the 2nd argument rather than the first? Which line is throwing the error, specifically?$endgroup$
– Mathieu Guindon
25 mins ago