Thema Datum  Von Nutzer Rating
Antwort
Rot VBA Code in Onenote speichern
20.04.2024 18:12:00 GTA
NotSolved
20.04.2024 22:38:38 Gast01
NotSolved
22.04.2024 16:43:45 GTA
NotSolved
22.04.2024 21:00:23 Gast01
NotSolved
26.04.2024 10:53:41 Gast32422
NotSolved
26.04.2024 22:01:07 ralf_b
NotSolved

Ansicht des Beitrags:
Von:
GTA
Datum:
20.04.2024 18:12:00
Views:
73
Rating: Antwort:
  Ja
Thema:
VBA Code in Onenote speichern

Hallo zusammen

Mithilfe dieses Codes will ich alle meine VBA Codes, Module von Addins als Text nach Onenote sichern. Damit das verfügbar bleibt.
Damit will ich meine Codes Backupen. Ich weiss dass man die Addins direkt als Backup kopieren kann. Der Vorteil von Onenote ist, wenn man ein Codeschnipsel sucht, und man nicht mehr weiss, wo man das gebraucht hat, dann kann man dort suchen. Deshalb das Ganze.

Nun ist es so, dass bereits bei der 2ten Zeile eine Fehlermeldung kommt: Benutzerdefinierter  Typ nicht definiert.

Sub SaveVBAtoOneNote()
    Dim objOneNoteApp As OneNote.Application
    Dim objOneNotePage As OneNote.Page '=> Hier 
    Dim strNotebookName As String
    Dim strSectionName As String
    Dim strPageName As String
    Dim strVBAContent As String
    
    ' Set your OneNote notebook, section, and page names here
    strNotebookName = "Testbook"
    strSectionName = "Testregister"
    strPageName = "Testseite"
    
    ' Get the VBA code to save
    strVBAContent = ThisWorkbook.VBProject.VBComponents("Module1").CodeModule.Lines(1, ThisWorkbook.VBProject.VBComponents("Module1").CodeModule.CountOfLines)
    
    ' Initialize OneNote application
    Set objOneNoteApp = New OneNote.Application
    
    ' Create or get the page
    Set objOneNotePage = GetOrCreatePage(objOneNoteApp, strNotebookName, strSectionName, strPageName)
    
    ' Append VBA code to the page
    objOneNotePage.Content = objOneNotePage.Content & vbCrLf & "```vba" & vbCrLf & strVBAContent & vbCrLf & "```"
    
    ' Release OneNote objects
    Set objOneNotePage = Nothing
    Set objOneNoteApp = Nothing
    
    MsgBox "VBA code has been saved to OneNote successfully!", vbInformation
End Sub

Function GetOrCreatePage(ByRef objOneNoteApp As OneNote.Application, ByVal strNotebookName As String, ByVal strSectionName As String, ByVal strPageName As String) As OneNote.Page '=> Hier auch
    Dim objNotebook As OneNote.Notebook
    Dim objSection As OneNote.Section
    Dim objPage As OneNote.Page '=> Hier sowiso
    
    ' Iterate through notebooks to find the specified one
    For Each objNotebook In objOneNoteApp.GetHierarchy.Children
        If objNotebook.Name = strNotebookName Then
            ' Found the specified notebook
            ' Check if the section exists
            For Each objSection In objNotebook.Sections
                If objSection.Name = strSectionName Then
                    ' Found the specified section
                    ' Check if the page exists
                    For Each objPage In objSection.Pages
                        If objPage.Title = strPageName Then
                            ' Page already exists
                            Set GetOrCreatePage = objPage
                            Exit Function
                        End If
                    Next objPage
                    ' Page doesn't exist, create one
                    Set objPage = objSection.AddPage(strPageName)
                    Set GetOrCreatePage = objPage
                    Exit Function
                End If
            Next objSection
            ' Section doesn't exist, create one
            Set objSection = objNotebook.AddSection(strSectionName)
            Set objPage = objSection.AddPage(strPageName)
            Set GetOrCreatePage = objPage
            Exit Function
        End If
    Next objNotebook
    
    ' Notebook doesn't exist, create one
    Set objNotebook = objOneNoteApp.CreateNewNotebook(strNotebookName)
    Set objSection = objNotebook.AddSection(strSectionName)
    Set objPage = objSection.AddPage(strPageName)
    Set GetOrCreatePage = objPage
End Function
Der Onenoteverweis ist aktiv: Onenote 15.0 Object Library
Der Pageeintrag gibt es aber nicht. Gibt es eine Alternative?

Ich habe gelesen, dass es eine 16.0 Variante der Bibliothek geben soll, ist der Eintrag vielleicht dort vorhanden?

 

Gruss und schönes WE

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot VBA Code in Onenote speichern
20.04.2024 18:12:00 GTA
NotSolved
20.04.2024 22:38:38 Gast01
NotSolved
22.04.2024 16:43:45 GTA
NotSolved
22.04.2024 21:00:23 Gast01
NotSolved
26.04.2024 10:53:41 Gast32422
NotSolved
26.04.2024 22:01:07 ralf_b
NotSolved