Make VB.NET app compatible with Office 2007 - vb.net

I just finished developing a custom VB.NET App for a client that relies heavily on automation of Powerpoint through Microsoft.Office.Interop.Powerpoint. It works great on my computer (running Windows 8, Office 2010, and Visual Studio 2010), but it fails to install on my client's computer, which runs Windows 7 and Office 2007. I think the issue is the reference to the "Microsoft Office 14.0 Object Library" and "Microsoft.Office.Interop.PowerPoint" ver 14.0, but I have no idea how to change the references to version 12.0, which presumably would be compatible with Office 2007.
The only versions available in "References" in my Visual Studio are the 14.0 ones. Is there any way to get a hold of older versions, or to otherwise make my app backwards compatible?
The error my client sees when trying to install says "application requires that assembly Microsoft.Interop.Powerpoint Version 14.0.0.0 be installed in the Global Assembly Cache (GAC) first."

I've done this in the past for Word and I suspect it can work for PowerPoint as well.
But it can be a bit risky, but this is one area where VB.Net actually shines :)
Essentially, you develop with a debug version and deploy with a release version and the objects use different binding types. Conditional compilation controls the switch between the two methods of binding.
Caveat: I haven't tried this, but it should be very close to what you're after.
' Code for where you declare you your objects...
#If DEBUG Then
' Create the object for the dev environment using early binding
Protected PowerpointApp As PowerPoint.Application = Nothing
Protected PowerpointDoc As PowerPoint.Document = Nothing
#Else
' Create the object for the compiled application using late binding
Protected PowerpointApp As Object = Nothing
Protected PowerpointDoc As Object = Nothing
#End If
' Code for where you create your objects...
#If DEBUG Then
' Declare the object for the dev environment using early binding
PowerpointApp = New PowerPoint.Application
#Else
' Declare the object for the compiled application using late binding
PowerpointApp = CreateObject("POWERPOINT.APPLICATION")
#End If
' Use whichever method you want to open the document
PowerpointDoc = PowerpointApp.Documents.Open(etc, etc, etc, ...)

Related

PowerPoint Plugin - Error - HRESULT E_FAIL has been returned from a call to a COM component

I have a problem debugging a project in specific scenario. I'm writing a PowerPoint plugin and when using it with Office 365, it throws following exception
PowerPointApplication_PresentationOpen - Exception: Error HRESULT
E_FAIL has been returned from a call to a COM component. Details:
at
System.Runtime.InteropServices.ComTypes.IConnectionPoint.Unadvise(Int32
dwCookie) at
Microsoft.Office.Interop.PowerPoint.EApplication_EventProvider.remove_AfterNewPresentation(EApplication_AfterNewPresentationEventHandler
) at
Microsoft.Office.Interop.PowerPoint.EApplication_Event.remove_AfterNewPresentation(EApplication_AfterNewPresentationEventHandler
) at
UI.ThisAddIn.?????????????????????????????????????????(EApplication_Event
, EApplication_AfterNewPresentationEventHandler ) at
UI.ThisAddIn.set_PowerPointApplication(Application WithEventsValue)
at UI.ThisAddIn.?????????????????????????????????????????(Presentation
)
Here's the code where its throwing exception
Private Sub PowerPointApplication_PresentationOpen(ByVal Pres As PowerPoint.Presentation) Handles PowerPointApplication.PresentationOpen
PowerPointApplication = Pres.Application
...
Here are the pre-requisite to reproduce the issue
Office 365
Create Presentation and Save It
Now, open presentation using PowerPoint open feature and not from recent.
and above exception will occur.
I'm using CopyLocal = True. However, when i change Microsoft.Office.Interop.PowerPoint setting to "Embed Interop Type" to True and "CopyLocal" to False then it works fine. Can we fix it by keeping CopyLocal property to True?
However, when i change Microsoft.Office.Interop.PowerPoint setting to "Embed Interop Type" to True and "CopyLocal" to False then it works fine. Can we fix it by keeping CopyLocal property to True?
This is a good indicator that something is wrong with your interop assemblies. I'd recommend generating new interop assemblies by removing existing COM references and then re-adding new COM references in Visual Studio. Or just download them from the download center, for example, see Microsoft Office 2010: Primary Interop Assemblies Redistributable. There are no newer versions available, so you can generate them in Visual Studio.

declare public variable types based on OS

I am editing a VBA macro that has worked for Office 2003, 2007, 2010, 2013 etc, on any previous OS version of windows we've used. Now that we've upgraded to windows 10, this line of code:
Private m_document As MSXML2.DOMDocument
Doesn't work. It needs to be
Private m_document As MSXML2.DOMDocument60
In context, I am declaring explicit global variables, and this is one of them.
Problem is, I need to edit these macros on my computer, but they need to also work on older OS versions because the product is still used on those versions. I have tried a bunch of stuff to figure out if there's any way to make this work otherwise, no dice. MSXML6 is on both my old (running windows 7) and new computer. So at this point, my hope is for there to be a way to define this variable depending on which OS is being used. I know you can check the OS, I've found code for that, but is there a way to conditionally define the variable based on the OS?
ie:
if windows10
Private m_document As MSXML2.DOMDocument60
else
Private m_document As MSXML2.DOMDocument
You need to use late binding.
Private m_document As Object
Sub testSub()
If windows10 Then
Set m_document = CreateObject("MSXML2.DOMDocument60")
Else
Set m_document = CreateObject("MSXML2.DOMDocument")
End If
End Sub
As a bonus tip, if you do this, you will lose the intellisense in VBA. So, you can set it as "Private m_document As MSXML2.DOMDocument60" and create all of your code with intellisense and then once you are ready to deploy, change back to late binding as above.

Cannot create VB6 ActiveX dll

I am trying to create a simple VB6 ActiveX exe and call it from Excel.
In VB6 I create an ActiveX DLL project called BigTrev, using all the default settings.
I create a MultiUse class called Trev with a single method containing no code
Public Sub HelloWorld()
End Sub
I make a DLL and register it from the command line (VB6 also registers it for me but I did it using cmd as well anyway).
Then it Excel I create a reference to my DLL in a new workbook. It clearly has been registered because the Intellisense knows about Trev and HelloWorld.
Sub cats()
Dim derek As BigTrev.Trev
Set derek = New BigTrev.Trev
derek.HelloWorld
End Sub
It compiles in Excel, when I step through it it fails in the second line, the Set one. Error message is "ActiveX component can't create object".
Why? I have done this or similar loads of times many years ago when VB6 was used widely, I am using Windows 7 now and I am an admin on my box.
I would suggest registering the DLL (or EXE if that's the direction you've chosen) with the relevant regsvr32.exe. In this case, where you're registering a 32bit DLL for use in 64bit environment, use the one hiding out in c:\windows\syswow64.
Sadly, I don't have Excel (shock, horror) and the spreadsheet I do have (LibreOffice) is 32bit.

Excel oleobject cannot delete

I put date picker to my sheet and got a lot of problem
I cant select or delete thoose dtpickers nor manualy nor from VBA as this code
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
obj.Delete
End If
Next
Return an error
application defined or object-defined error
I using Office 2013 32bit, other computers with Office 2010 32bit, Office 2007 32bit, Office 2013 32bit. I cant run compiled workbook on others computers, as i get in refences missing
microsoft windows common controls 2 6.0 sp6
Which also cannot be removed as is in use. I cannot uncheck it.
Most of my project functions and parameters such (Ucase, Mid, Left, wdAlignParagraphLeft) start getting error as undefined. Also all undeclared variables got the same error. Solving only by writing it with prefix VBA.Ucase, VBA.Mid and etc. and declaring all variables.
Also in developer tab insert control button not active anymore in all computers also in my computer too.
So question is? how to delete thoose dtpickers object and fix my project?
How to know what depend to microsoft windows common controls 2 6.0 sp6 library?
Remove protection from your sheet and then select and delete objects, after that go to VBA editor and uncheck this library from references and restart your Excel application.

Outlook.Application not defined

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.