How to port OneNote 2010 vba scripts (hosted in a XLSM file) to work in Onenote 2016 - excel

I would need help to get unstuck in porting from Onenote 2010 to OneNote 2016 an Excel VBA host toolkit I made
TLDR:
a) what object libraries should I actually see/reference if I want to use Excel 2016 VBA host to automate OneNote 2016 (desktop app)? I seem to be able to link only to Onenote 12 object library, there is a V15 libray but yields "name conflict" error when I try to reference even if I unclick the rest. Is my installation wrong? (Win10+Excel/ON 2016 32 Bits)
b) how the vba call to getpagecontent() should be in OneNote 2016, in particular what is the schema parameter, a string constant?, should I care?
Longer version
In https://github.com/jceresearch/onenote_vba_host (public) , I maintain an Excel spreadsheet with a few scripts to do things like exporting in bulk pages as an individual doc/pdf, including its embedded files alongside. Also does auto numbering of pages, and auto adding things in pages. It adds a menu in the ribbon you can see there the options.
The code is messy but works with Onenote 2010 fine. I will need soon to work in 2016.
The key part of the 2016 code is in the class code, to call the OneNote up:
Set app = New OneNote12.Application
In my 2010 code/installation it is already OneNote14.Application, but the version of office 365 I have allows me to refer to the Onenote12 object library only.
There is also a "Microsoft OneNote 15.0 types" library but when I click it it yields error of name conflict, even if I remove the old library. There is also an extended type library that again Excel doesn't let me refer to.
So current referenced libraries are:
Microsoft Office 16.0 object library (needed for the extra ribbon element added)
Microsoft OneNote 12.0 object library
Microsoft XML, V3.0 (I had to downgrade from the V6 that Excel suggests by default)
Microsoft Forms 2.0 Object library
Microsoft VBScript Regular Expressions 5.5
With these, I can run the macros and call the OneNote app, even get the list of notebooks and sections.
However, OneNote crashes miserably when the host tries to run:
app.getPageContent sNodeID, sXML, piAll
I tried a few things like bringing just the basic data but same results, also tried various other notebooks, pages, sections.
I assume the issue may have to do with the old version of the object library and/or that in the documentation of getpagecontent there is a mention to using the xsSchema parameter (xs2013 etc). See https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote
Any ideas welcomed, and btw, if someone wants to help improve the toolkit, more than welcomed, get in touch.
Thanks!

Here is the solution I found by trial and error:
a. I made a silly mistake I didn't realise till I tested things in isolation. My class name I believe clashed with one of the newer libraries (clsOneNoteHandler possibly). Changing to a unique name seemed to solve most of the problems, notably preventing the load of the latest object library and ultimately making OneNote crash.
b. I managed to link to the Onenote 15.0 object library (not the extended one), and that seems to be compatible with my 2010 code. I noticed it runs noticeably slower (same machine after re imaging to windows 10 with office 2016 32 bits).
c. I Still kept the Microsoft XML, V3.0 library referenced and syntax to parse the onenote XML content, and works fine as far as I can see.
I need to keep regression testing it, but to me the most important feature was to to export pages as docs and its embedded files, and that still works in Onenote 2016.
Hope this will help someone somewhere there.
Regards and thanks for the comments!

Related

How to create an installation file for a document-level VSTO template?

This is hardly the first time this question has been asked, but there are no completely satisfactory answers that have been presented, and nearly ALL of them rely upon Microsoft's error-laden developer documentation.
After creating a vb.net VSTO Excel Template project using Visual Studio 2019 with Office 2016 and porting exiting VBA code to vb.net, I have run into a brick wall. I was able to convert the code to vb.net without too much trouble, and thanks to the .net libraries, I was able to include additional functionality that before was impossible with VBA (e.g. Action Panel menus, etc.). But now I cannot distribute the solution to my employees because I cannot create a setup file that will allow the template code to run correctly when the resulting document is saved to any location other than where it was first installed.
I have tried using the supposedly simple ClickOnce method. I have tried the Windows Installer method. We don't have a Sharepoint server (we are a small company) and I don't want to learn how to create one. I have followed the examples at
https://learn.microsoft.com/en-us/visualstudio/vsto/deploying-an-office-solution-by-using-windows-installer?view=vs-2019
and
https://learn.microsoft.com/en-us/visualstudio/vsto/deploying-an-office-solution-by-using-clickonce?view=vs-2019
and
https://learn.microsoft.com/en-us/visualstudio/vsto/deploying-a-vsto-solution-by-using-windows-installer?view=vs-2019#to-build-the-setup-project
and several other Microsoft Visual Studio VSTO instructional articles to no avail. I still cannot get the resulting template file to reference the necessary libraries when the template is moved or saved to any location on a user's computer other than its original install folder. This pretty much makes the solution useless to me. You would think something this important to so many VBA users would be a priority to Microsoft, but it clearly is not. Microsoft refuses to fix/update its documentation, and it ignores vb.net like Microsoft's own policies had nothing to do with why so many of us use it.
I would post my code, but I have no idea what code, in what has now become a rather complicated solution, is causing the problem. My only clue is the error message, which appears whenever the Excel workbook is saved somewhere else and states that "my solution".vsto could not be downloaded because Office is looking under where the template is now stored rather than the original installation directory.

Office-JS: Excel Host API no longer available under Excel 2016 MSO

I'm currently running Windows 10 with Microsoft Excel 2016 MSO (16.04266.1001) 64-bit. I'm under the impression that that is the version installed via MSI.
Over the course of the last few months I've implemented a React-based Excel add-in using the Excel Host APIs. Per the Excel JavaScript API requirement sets document available at the Office Dev Center, that build appears to contain the "ExcelApi 1.1, WordApi 1.1, and common API" requirement sets.
As of yesterday, I am no longer able to access the Excel host APIs through JavaScript or through the F12 developer tools (window.Excel === undefined). It appears that all the functionality under that had previously existed under that namespace has become unavailable.
It appears that (among other scripts), the office.js script loaded from the CDN now requests and embeds Excel-15.02.js for the add-in.
I do not know the version of Excel-*.js that was being embedded before yesterday, but after perusing the contents of both Excel-15.02.js, Excel-winrt-16.00.js and other versions available on the CDN, I suspect that it was a later version than 15.02.
For the record, both of the following runtime checks return false - I say both, because "API" is capitalized inconsistently in the documentation available at dev.office.com.
Office.context.requirements.isSetSupported("ExcelApi", 1.1); // false
Office.context.requirements.isSetSupported("ExcelAPI", 1.1); // false
Please advise; best regards.
I am investigating the issue. A few questions:
You mention that the files being loaded include Excel-15*.js files. How are you seeing this -- is it through Fiddler, or through a debugger? If you can send a Fiddler trace, that would be really useful (a Fiddler trace may contain some sensitive info, so you may want to scrub it -- and feel free to send it to me directly rather than posting it here online)
If you browse to https://appsforoffice.microsoft.com/lib/1/hosted/office.js in a browser, what is the version number that you see at the top of the file?
If you are comfortable deleting your IE cache: could you see if the issue continues to repro even after you've cleared the cache?
Feel free to reply here via comments, or as updates to your questions, or to email me directly. My email is my full name (separated by a dot between first and last) at microsoft.com.
I will be updating this answer as I have more info.

Excel 2010 late binding on Access 2010 Project

So i have this typical problem of distributing an Access application to a client. The application is written in Access 2010 and recently i addded some code to export Excel sheets. Therefore i added the excel object library version 14.0.
My clients that run Excel 2007 cannot run the application anymore getting the infamous error: "mssing or broken reference to the file excel exe version 1.7". The question is this:
If i use LateBinding, will the added functionality be available to them ?
I wish to apologise if the question sounds naive but i am new to VBA.
Yes, the functionality should be available, UNLESS you use features that were not available in 2007 (Some table theme formatting using patterns for example is 2010plus) then you should have no issues using late binding.
I guess the easiest is to simply try. Ideal would be to have a virtual PC running Office 2007 and develop using that, when you are targeting client using a lower version than yourself.
Hope that helps.

How to write to an excel document without having microsoft excel not installed on the server?

I was wondering, if I don't have excel office product not installed on my server, how can I write to an excel document using .net code? I know there's a Microsoft.Inerop.Excel assembly that will assits in this, but it doesn't work for me. I get a CLSID id error where is looking for this particualr guid, but its not installed on my machine. I have the Interop assemblies installed on my server, but I can't use the Excell.Application object. Is there another object that i can use instaed of Excel.Application() to create an excel document on a server where the offce excel product is not installed on? Also my box is 64 bit running SharePoint, if you have any alteratives using SharePoint 2010 I would like to hear about them as well.
Thank You,
There are several Third Party tools, commercial ones like Spire.xls (which we have used, and it works quite well) and freeware, like excellibrary (http://code.google.com/p/excellibrary/).
This has been asked before, see Create Excel (.XLS and .XLSX) file from C# (guess someone may close that question).

Excel OLE - .NET COM AddIn behaves differently when Excel is embedded in an application

I have a .NET (C#) addin that uses a COM Shim dll to load itself into Excel. The addin works fine without any problem when Excel is run normally. The addin displays its own custom toolbar in Excel that is used to execute different commands.
When I embed Excel into another application (e.g. DSOFramer etc), the addin starts behaving strangely. It seems that if I disable a button on its toolbar then it does not get enabled again after setting the Visible property.
Also, I get a bunch of "Object reference not set" errors because the Application::Selection object is NULL which never happens when Excel is running normally. Sometimes I also get permission errors when Application::GetAddIns() method is called.
I am not sure what is happening here and I could not find an articles that explains the behavior of Excel COM Addins when Excel is embedded inside other application.
I have to admit I don't know much about dSOFramer, but I did run across the following items. I don't know if these help at all.
link text
link text
I contacted Microsoft Professional for this issue and found out that Microsoft now discourages embedding office applications. I was suggested to either stop embedding Excel into the application OR use only Excel 2007 that has a Ribbon UI. According to MS, the Ribbon UI does not have these issues.
The problem with the CommandBars is that the negotiation only happens during the OnConnection and no changes can be made afterwards.

Resources