I inherited the below macro someone wrote in Powerpoint and it is filled with code I don't quit understand. I am getting an error on the For Each line and am wondering if the reason is that I am missing a reference library that needs to be checked. Unfortunately, I cannot get ahold of the creator so I am just wondering if there is a certain reference I need activated to get ahold of the WebResponse properties
Dim versaries As WebResponse
Dim versary As Object
Set versaries = New WebResponse
Set versaries.Data = WebHelpers.ParseJson(ReadTextFile())
For Each versary In versaries.Data '<--- ERROR LINE
'......
Next versary
Run-time error '438':
Object doesn't support this property or method
The only references currently activated on PP VBA Editor are
Visual Basic For Applications
Microsoft PowerPoint 16.0 Object Library
OLE Automation
Microsoft Office 16.0 Object Library
Related
I'm following this mail merge work that I found in a related Stack Exchange question which looks to do something similar to what I'd like but I'm having trouble getting started. I"ve narrowed the problem down to the below...
Sub TestEmailer()
Dim Source As Document, Maillist As Document, TempDoc As Document
End Sub
With the error "User-defined type not defined."
It appears I'm missing a reference, but the reference recommended "Microsoft Office 16.0 Object Library" doesn't seem to fix the issue when I enable it.
Has this Document object moved to a different library? How do I find the right library in the future?
If you're doing this in Excel, you need to add a reference to Microsoft Word 16.0 Object Library and then use:
Sub TestEmailer()
Dim Source As Word.Document, Maillist As Word.Document, TempDoc As Word.Document
End Sub
Each application will only load it's own objects by default, along with other common Office objects. If you want to use other objects from another application you either need to add a reference to that application's object library or use late binding.
In this instance I'd recommend early binding (adding a reference manually) so that you get the benefit of IntelliSense in your code, this will make it easier working across applications.
Im building an windows-form-application which will do some automation using Outlook Interop (its not a vsto addin). And this is working fine with all version except outlook 2007 which generating an error message when initiating Dim oApp As New Outlook.Application (Error: Object reference not set to an instance of an object ) But just after throwing the error it starts the process outlook.exe by itself, however its not performing any tasks onward.
Note: the app will only work when no outlook instance is running, so this shouldn't have any conflict with creating new instance New Outlook.Application. Im using visual studio 2017.
Imports Microsoft.Office.Interop '(Version 14.0)
Public Sub Form_Startup() Handles Me.Load
If Not IsProcessRunning("OUTLOOK") Then
DoSomething()
End If
End Sub
Public Sub DoSomething()
Dim oApp As New Outlook.Application
Dim oNspace As Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim oStores As Outlook.Stores = oApp.Session.Stores
Dim dFolder As Outlook.Folder
'Some code here
'Some other code here
Runtime.InteropServices.Marshal.ReleaseComObject(oApp)
Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp)
oApp = Nothing
End Sub
On the other hand I've also tested this DoSomething() part in a vsto addin which works fine in all version including 2007 without error.
Update:
Using the following advises from fellow experts still not solving my issues in outlook 2007. I've followed the late binding along with direct version referencing to outlook 2007 as advised by #aduguid didn't solved the error message. Maybe Im miss understanding the feedback getting from the comments here.
Dim outlook As Object = Nothing
outlook = CreateObject("Outlook.Application.12")
The main goal of this is to build an automation app for outlook which will work on all outlook version (e.g 2007,10,13,16), My above code is working fine with all upper version except 2007. I had to test in all office version separately for which im using separate VM while my development environment is setup with Visual Studion 2017.
Here's an example of late binding with the specific version of Outlook.
Dim outlook As Object = Nothing
outlook = CreateObject("Outlook.Application.12")
I have a great Monte Carlo simulation macro for MS Project that I use all of the time. Since I upgraded my version of MS Office, it no longer works.
I got the macro from the following link: https://sourceforge.net/projects/montecarloprj/?source=typ_redirect
It generates an error (Compile error: User-defined type not defined) at the following line:
Sub SetupExcel(ByRef XlApp As Excel.Application, ByRef XlBook As Excel.Workbook)
Previously, to resolve this issue I needed to enable "Microsoft Excel 12.0 Object Library" in Tools-References in VBA. However, that option (or any Excel Object Library) is not available.
If you can't find the object library on the list, you can use the Browse button to add it to the list yourself. Find out where the excel.exe file is located and use the Browse... button in the References dialog box. Be sure to change the file type to Executable Files when adding the reference (lower-right corner of the Add Reference dialog box).
I wrote a powerpoint add-in that works well on my local computer. Yet when I email the file to others, all of a sudden half the functionalities no longer work and show the compile error as listed in the subject line.
Digging a bit deeper, it appears the issue is that the client computers do not have the correct reference libraries (e.g., Excel 14.0 Object Library, Outlook, Access, etc.). I have these libraries correctly referenced when writing the add-in as a pptm file, but imagine that when I saved the pptm into a ppam file, the reference libraries were "lost" somehow.
Does anyone have any ideas? Note that adding the reference libraries directly on the client computers does not appear to help. Instead, I'd need to send the client the foundational pptm file, add the reference libraries, then save that file as a ppam file on the client computer directly, which of course is not practical. So how does one "embed" reference libraries to the add-in?
Thank you!
So how does one "embed" reference libraries to the add-in?
You don't.
Alternative:
Instead of Early binding, use Late Binding.
Example code of Early Binding.
Here we set a reference to MS Word xx.xx Object Library.
Sub Sample()
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = New Word.Application
Set oDoc = oWrd.Documents.Open("....")
'
'~~> Rest of the code
'
End Sub
Converting the above to Late Binding.
Here we do not set the reference but let the code bind to whatever version of MS Word is present in the destination pc.
Sub Sample()
Dim oWrd As Object
Dim oDoc As Object
Set oWrd = CreateObject("Word.Application")
Set oDoc = oWrd.Documents.Open("....")
'
'~~> Rest of the code
'
End Sub
Similarly you can change your code for MS-Excel as well.
For Further Reading
I have Microsofr Office Professional Plus 2010 version 14.0.6029.1 installed.
I have the following reference in a VB project:
Microsoft.Office.Enterop.Outlook
The type is .NET and the version id 14.0.0.0
My code includes the following:
Dim objOutlook As Outlook.Application
the following error appears:
"Error 14 Type 'Outlook.Application' is not defined. "
I'm stumped.
I'm in the process of upgrading several projects from XP to Win7 as well, and I ran into this problem a few weeks back.
Try this,
Go to Project Properties -> References -> Add -> Click COM Tab -> Scroll down to either "Microsoft Outlook 14.0 Object Library" or "Microsoft Office 14.0 Object Library". (Pretty sure it needs to be the Outlook one).
In my solution, when I right click on Dim objOutlook As Outlook.Application and go to definition, it is a member of Microsoft.Office.Interop.Outlook, which comes from the Microsoft.Office.Interop.Outlook DLL
This worked for me, so I hope it helps you.
Is there a namespace conflict with Outlook that the code is perhaps trying to reference a different object?
Try aliasing your Imports directive:
Imports Outlook = Microsoft.Office.Enterop.Outlook
This should explicitly tell your code (specifically your Dim statement) to use that namespace instead of any other implied Outlook namespace.
for 2016 excel version make sure the below is ticked:
tools-->references----->
*Microsoft outlook 16.0 object library,
Microsoft Office 16.0 Object Library,
Microsoft Access 16.0 Object Library.