Using OneNote 16 and I am trying to open Onenote Through VBA However getting an error - Automation error/Library not registered.
Microsoft Onenote 15.0 library has already been selected.
I am trying below which is not working and getting an error in the line
onApp.OpenHierarchy folderPath & fileName, ""
And the rest of the code below.
Sub ModifyOneNoteFilesInFolder()
Dim folderPath As String
Dim fileName As String
Dim onApp As Object
' Specify the folder path where your OneNote files are located
folderPath = "C:\Users\YourUser\Desktop\YourFolder\"
' Create OneNote application object
Set onApp = CreateObject("OneNote.Application")
' Loop through all .one files in the folder
fileName = Dir(folderPath & "*.one")
Do While fileName <> ""
' Open the OneNote file
onApp.OpenHierarchy folderPath & fileName, ""
' Add the text "Testing" to the current page
onApp.Windows(1).ActivePage.Content.ExpandOutline
onApp.Windows(1).ActivePage.Content.AppendLine "Testing"
' Save the modified OneNote file
onApp.Windows(1).ActivePage.Save
' Close the OneNote file
onApp.Windows(1).Close
' Get the next file in the folder
fileName = Dir
Loop
' Clean up
Set onApp = Nothing
End Sub