ActiveX cannot create object on Set outA = CreateObject("Outlook.Application") - outlook

I have a legacy VB6 application to allow a user to send an email from the application itself.
Dim outA As Outlook.Application
Set outA = New Outlook.Application
If outA Is Nothing = True Then
'Outlook is not open... so need to create a new outlook
Set outA = CreateObject("Outlook.Application")
End If
In Windows 7 Office 2007 it works. User can have Outlook open and it works with no issues.
In Windows 10 Office 2016 this code does not work. It gives me an error on
Set outA = New Outlook.Application.
If Outlook is not open, the code works. I'm only getting this error if Outlook is open.
The error is...
ActiveX cannot create object error 429.
I have local privelages on my computer.
If I open my VB6 .exe explicitly as ADMIN and Outlook as ADMIN as well - the code gives me no issues.
I have UAC prompt disabled.
I cannot give ADMIN rights to user.
Am I missing a dll or something? I have a few more applications that have been used in Windows 7 and I have not had this issue.

Keep the early binding for development and once complete, scrap it for the late bind. Don't forget to remove the reference to Microsoft Outlook xx Object Library in VBE.
Early binding:
Dim outA As Outlook.Application
Set outA = New Outlook.Application
Late Binding:
Dim outA As Object
Set outA = CreateObject("Outlook.Application")
The reason is that early binding references a specific version of Outlook e.g. Microsoft Outlook 14.0 Object Library which is specific for Office 2010, so if it's not available it throws an error. The reference itself is marked with a "missing".
The late binding's CreateObject("Outlook.Application") takes care of that.

Repare office and ok (for me that was the solution)

Related

MAPI Error : The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]] [duplicate]

We are upgrading our server to Windows 2012 from 2003.
Our application use CDO 1.21 and MAPI to send mails, I know I have to use SMTP/ OOM/AWS. At this late stage I don't want to do make changes in our programs right now - there are 80+ :)
When I am going to MS site to download CDO 1.21, Windows 2102/Exchange Server 2010 SP3 is not specified under supported platforms.
I am able to download CDO 1.21 for Win 2012. But now when I am connecting via MAPI, System is throwing error:
The information store could not be opened. [MAPI 1.0 - [MAPI_E_LOGON_FAILED(80040111)]]
MAPI Code :
Set objMAPI = New MAPI.Session
objMAPI.Logon ShowDialog:=False, NewSession:=False, ProfileInfo:=gobjINI.gstrExchangeServer & vbLf & gobjINI.gstrProfile
'Add a new mesage to the OUtbo Messages Collection
Set objMSG = objMAPI.Outbox.Messages.Add
Error is thrown on third line: Set objMSG = objMAPI.Outbox.Messages.Add.

vb6 installation on Win 8.1

For several years I have been running a compiled VB6 program on an church office computer. I had the vb6 program installed on my home computer (Win 7) This program ran without problems. The program opened Excel spreadsheets and allowed the user to manipulate the data on the spreadsheet.
My Windows 7 computer crashed. I have a Windows 8.1 computer and have loaded vb6 on this computer. The installation appears to be successful except when I run the same visual basic project I get a Runtime Error '-2147319779 Automation Error Library not registered.' A sample of my code is shown below:
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
oExcel.Workbooks.Open ("C:\FPCE Financial\FY-2014\2014-01 Financials.xls")
Application.Visible = True
The error occurs on the "Set oExcel = Excel.Application" line.
Any help would be appreciated.
If you haven't set a reference to Excel you need to use "Late Binding" to create the Excel object. As #Noodles says - if you don't have Office installed, it won't work period.
Try changing this
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
To this
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")

Outlook error Retrieving the COM class factory

We have a functionality to add contacts to outlook.
I simply want to do it to existing outlook process if one is running or open if not running.
I get error:
Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005 Server execution failed (Exception from HRESULT:
0x80080005 (CO_E_SERVER_EXEC_FAILURE)).in case the process in not
already running.
Note: the below method is called 2 times.
My code is:
Private Sub InitObject()
If (Process.GetProcessesByName("OUTLOOK").Count > 0) Then
objOutlook = DirectCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application)
'If objOutlook Is Nothing Then
Else
objOutlook = New Outlook.Application()
End If
If objNamespace Is Nothing Then
objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon("", "", False, False)
End If
If objFolder Is Nothing Then
objFolder = objNamespace.GetDefaultFolder(10)
End If
End Sub
I read several posts on this saying admin privileges and all. Now I am running Visual Studio without Admin rights. I am sacred is this error will be seen in production too where we don't use Visual Studio?
What Outlook version do you have installed on the problematic PC? Is it the Click2Run edition of Outlook 2010?
Anyway, I see two possible causes for that:
You have got the Click2Run edition of Office 2010 installed on the PC. The fact is that the Click2Run edition of Office 2010 doesn't support automation. See Office 2010 Click-to-Run compatibility with add-ins for more information. Also you may find the How to: Verify Whether Outlook Is a Click-to-Run Application on a Computer article.
Your program and MS Outlook must both be run as administrator or as normal privilege level. They should be under the same privileges. You may find the How to self-elevate an application to a high privilege level under UAC article helpful.
Be aware, Outlook is a singleton. I.e. if it is already running, you will get a pointer to the already running instance when you create a new Outlook Application instance.

Presentations.Open requires PowerPoint 2007 to be open?

I have a macro runTest in a PowerPoint file test.pptm that I wish to call by using the following VB script. All works well when the script is called on a machine with Office 2010, but the script will only work with Office 2007 providing the PowerPoint application has been opened before calling the script. I'd be interested to hear whether anyone has experienced a similar problem, or to hear of any potential solutions.
Option Explicit
On Error Resume Next
RunProcess
Sub RunProcess()
Dim pptApp
Dim pptPresentation
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPresentation = pptApp.Presentations.Open("C:\test.pptm", True)
pptApp.Run "test.pptm!runTest"
pptApp.Quit
Set pptPresentation = Nothing
Set pptApp = Nothing
End Sub
I resolved the problem by adding
pptApp.Visible = True
after creating pptApp and before opening the presentation.
In the event that it needs Powerpoint launched, I would just trigger the launch as part of the vbscript
Set WshShell = wscript.CreateObject("wscript.Shell")
WshShell.Run "C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE"
You could build in some error handling to see which version is installed, and call the appropriate exe file

How can I programatically tell what Outlook addins are installed, and if they are enabled or not?

How do I determine what Outlook COM or PIA addins are installed, and if they are enabled or not.
How can I get this information, and hopefully the file version as well?
(1) If you want to access this information from inside another Outlook Add-in, you may use the the Application.ComAddins object (e.g. it's Count property gives you the number of add-ins installed). You can loop through this collection and check the LoadBehaviour property of the single COMAddin object to now if they're loading or if they're disabled.
(2) If you wand to access the information from outside of Outlook, you may consider to read the appropriate registry entries under the Software\Microsoft\Office\Outlook\Addins key.
(3) Please be aware that you cannot trust this information at all, because Office add-ins can be installed either for a single user or for all users. So you cannot access the installed add-ins absolutely, but only for the current user running your app /your procedure, by reading the abovementioned key (a) under HKLM and (b) under HKCU. The Application.COMAddins object shows you both information blended in one.
(4) I don't recall that a version number is available either in the COMAddin object or in the registry. To access that, you'll have to read the registry to find the file or assembly of the add-in, and access the file version. Please note that "old" COM Add-ins written in Visual Basic 6 or another language have other registry entries than VSTO add-ins or add-ins based on the Add-in Express tool.
To determine which installed add-ins are active (enabled/loaded):
'Loop through all installed add-ins and show whether they are active or not.
Dim app As New Outlook.Application
Dim name As String
Dim loaded As Boolean
For i = 1 To app.COMAddIns.Count
name = app.COMAddIns.Item(i).Description
loaded = app.COMAddIns.Item(i).Connect 'Returns True for active, False for inactive
MsgBox(name & ": " & loaded)
Next
To check the status of a specific add-in by name:
Dim app As New Outlook.Application
Dim addinName As String = "ADD-IN NAME"
Dim loaded As Boolean = app.COMAddIns.Item(addinName).Connect
MsgBox(addinName & ": " & loaded)
You can access that information even from outside of outlook.
Dim count As Integer
Dim app As New Outlook.Application
count = app.COMAddIns.Count
For i = 1 To count
MsgBox(app.COMAddIns.Item(0).Description)
Next

Resources