{"id":142,"date":"2009-01-16T13:48:41","date_gmt":"2009-01-16T13:48:41","guid":{"rendered":""},"modified":"2018-05-02T07:54:56","modified_gmt":"2018-05-02T06:54:56","slug":"dokumentenstruktur-reparieren","status":"publish","type":"post","link":"https:\/\/www.kastenmaier.de\/?p=142","title":{"rendered":"VBA &#8211; Word: Dokumentenstruktur reparieren \/ Navigation Pane Document Structure Fix [Update (2014-04-03)]"},"content":{"rendered":"<p style=\"text-align: justify;\">Auch wenn es naheliegend ist mit Hilfe des Inhaltsverzeichnisses durch ein Word-Dokument zu navigieren, falls es denn ein Inhaltsverzeichnis gibt, bietet sich daf\u00fcr doch auch die Dokumentenstruktur an.<\/p>\n<p style=\"text-align: left;\"><!--more--><\/p>\n<ul>\n<li><strong><a href=\"#deutsche_version\">Deutsche Beschreibung (Fortsetzung)<\/a><\/strong><\/li>\n<li><strong><a href=\"#english_version\">English version of the description<\/a><\/strong><\/li>\n<li><strong><a href=\"#src1\">Sourcecode &#8211; Variante 1 (alte Version) \/ Variant 1 (old version)<\/a><\/strong><\/li>\n<li><strong><a href=\"#src2\"><span style=\"line-height: 1.714285714; font-size: 1rem;\">Sourcecode &#8211;\u00a0Variante 2 (neue Version) \/ Variant 2 (new version)<\/span><\/a><\/strong><\/li>\n<\/ul>\n<h1><a name=\"deutsche_version\"><\/a>Deutsche Beschreibung (Fortsetzung)<\/h1>\n<p style=\"text-align: justify;\">Die Dokumentenstruktur bietet den Vorteil, dass sie beim Bearbeiten eines Textes einfacher anzuwenden ist, um zu bestimmten Punkten im Dokument zu springen. Hinzu kommt, dass beim Erstellen eines Dokumentes das Inhaltsverzeichnis evtl. noch gar nicht existiert oder nicht (immer) aktuell ist.<\/p>\n<p style=\"text-align: justify;\">Auch wenn die Dokumentenstruktur sehr hilfreich ist, gibt es mit ihr doch leider immer wieder Probleme. Probleme treten z.B. vermehrt auf, wenn man ein mit Word 2003 erstelltes Dokument in Word 2007 \u00f6ffnet, dann sieht die Dokumentenstruktur mitunter gar nicht mehr strukturiert aus. Aber nicht nur durch das verwenden einer anderen Word-Version kann die Anzeige der Dokumentenstruktur beeintr\u00e4chtigt werden. In solchen F\u00e4llen, wenn die Dokumentenstruktur nicht mehr korrekt angezeigt wird, hilft das folgende Makro weiter, dass die Dokumentenstruktur neu aufbaut.<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 1: <\/strong><\/span>Ich habe eine neue Variante zum Reparieren der Dokumentenstruktur hinzugef\u00fcgt. Diese arbeitet deutlich schneller als die alte. Der Ansatz ist allerdings auch ein anderer.<\/p>\n<p style=\"text-align: justify;\">Ein generelles Problem scheint aber sowohl bei der neuen, als auch bei der alten Variante zu bestehen: Die Dokumentenstruktur ist bei erneutem \u00d6ffnen des Dokuments wieder defekt. Der Grund hierf\u00fcr ist anscheinend ein automatisierter Mechanismus in Word (siehe hierzu auch die folgende Seite von Microsoft <a href=\"http:\/\/office.microsoft.com\/de-de\/word\/HP051896691031.aspx\" target=\"_blank\"><span style=\"color: #0000ff;\">Problembehandlung bei der Dokumentenstruktur<\/span><\/a>), der &#8211; f\u00fcr den Fall, dass auf den ersten paar Seiten kein Inhaltsverzeichnis oder ein Text, der mit einer der Standard-\u00dcberschriftenformatvorlage formatiert wurde, gefunden wird &#8211; automatisch nach dem \u00d6ffnen versucht, anhand des Erscheinungsbildes von Abs\u00e4tzen, Gliederungsebenen zuzuweisen und so die Dokumentenstruktur aufzubauen. Leider funktioniert letzteres nicht wirklich gut. <span style=\"text-decoration: underline;\">Wenn die korrigierte Dokumentenstruktur erhalten bleiben soll, ein Inhaltsverzeichnis allerdings (noch) nicht existiert, oder das Inhaltsverzeichnis zu weit hinten ist, kann man das automatische Neuaufbauen der Dokumentenstruktur durch dr\u00fccken von Esc beim \u00d6ffnen der Datei abbrechen.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 2: <\/strong><\/span>Mit beiden Makrovarianten kann es unter bestimmten Umst\u00e4nden zu Problemen (ungewollten Ergebnissen) kommen. F\u00fcr genauere Informationen sollte der folgende Beitrag auf MS Office 2007 &#8211; Hilfe angeschaut werden: <span style=\"color: #0000ff;\"><a href=\"https:\/\/web.archive.org\/web\/20091213041936\/http:\/\/www.office2007-hilfe.de\/word-hilfe\/dokumentstruktur-wird-nicht-angezeigt-t5489.html\" target=\"_blank\">Dokumentstruktur wird nicht angezeigt<\/a><span style=\"color: #000000;\">\u00a0(da die Seite mittlerweile nicht mehr existiert, verweist der Link jetzt auf die entsprechende Seite von\u00a0<\/span><a href=\"https:\/\/archive.org\">https:\/\/archive.org<\/a><span style=\"background-color: #ffffff; color: #000000;\">)<\/span><\/span><span style=\"background-color: #ffffff; color: #000000;\">.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 3 (2010-11-03): <\/strong><\/span><span style=\"text-decoration: underline;\">Am einfachsten kann man das Problem komplett umgehen, indem die Dokumentenstruktur beim Laden des jeweiligen Dokuments deaktiviert ist.<\/span> Wartet man dann so lange, bis Word das Dokument vollst\u00e4ndig geladen hat (das ist nicht der Fall, sobald es angezeigt wird, es dauert noch einen Moment) und schaltet erst dann die Dokumentenstruktur ein, wird sie korrekt dargestellt. Dieses Vorgehen ist meiner Meinung nach die einfachste und beste L\u00f6sung.<\/p>\n<p style=\"text-align: justify;\">Bei dem unter Update 2 erw\u00e4hnten Beitrag wird angesprochen, dass die \u201cneue Variante\u201d (M\u00f6glichkeit 2) des Makros die Gliederungsebene &#8222;ohne R\u00fccksicht auf Verluste&#8220; \u00e4ndert. Schaut man sich diese im jeweiligen Optionsfenster in Word allerdings an, sieht man, dass die Gliederungsebene nicht immer zu \u00e4ndern ist, sondern bei Standardformatvorlagen, wie z.B. \u00dcberschriften, ausgegraut und nicht \u00e4nderbar ist.<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 4 (2014-04-03):<\/strong><\/span> Jetzt auch mit englischer \u00dcbersetzung der Beschreibung und englischen Kommentaren im Sourcecode.<\/p>\n<h1><a name=\"english_version\"><\/a>English version of the description<\/h1>\n<p style=\"text-align: justify;\">It&#8217;s obvious to navigate through a Word document with help of a table of contents (if it exists), but the Navigation Pane lends itself for using. The Navigation Pane offers you the advantage of easier jumping to headings in the document during document creation and document editing. In addition, during document creation the table of contents may not even exist or not (always) is up to date.<br \/>\n<span style=\"line-height: 1.714285714; font-size: 1rem;\"><br \/>\nEven if the Navigation Pane is very helpful, from time to time it doesn&#8217;t work correct. For example: Problems occur increasingly when you open a document created with Word 2003 in Word 2007. Then sometimes the Navigation Pane doesn&#8217;t look like the table of contents anymore. But the document structure shown in the Navigaten Pane also can be affected by other reasons. In such cases, if the document structure in the Navigation Pane is not shown correctly, the following macro helps rebuilding the shown structure.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"line-height: 1.714285714; font-size: 1rem;\"><strong><span style=\"color: #ff0000;\">Update 1:<\/span> <\/strong>I added a new version of the macro. This works much faster than the old one. But the approach is also different.<br \/>\n<\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\"><br \/>\nHowever a general problem seems to exist in both versions: The shown document structure in the Navigation Pane is defective when opening the document again. The reason for this is apparently an automated mechanism in Word (see also the following Microsoft site\u00a0<a href=\"http:\/\/office.microsoft.com\/de-de\/word\/HP051896691031.aspx\" target=\"_blank\">Problembehandlung bei der Dokumentenstruktur<\/a> (only german version)). This mechanism automatically attempt after opening in case that on the first few document pages no table of contents or a text formatted with one of the default heading styles was found.\u00a0<\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\">The mechanism tries to allocate outline levels and to build up the document structure based on the appearance of paragraphs. Unfortunately, this functionality does not really work well. <span style=\"text-decoration: underline;\">In case that the shown document structure in the Navigation Pane is correct, but a table of contents not (yet) exist or the table of contents is not part of the first document pages, you can stop the automatic rebuilding of the Navigation Pane document structure by pressing Esc while opening the file.<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><strong><span style=\"color: #ff0000;\">Update 2:<\/span><\/strong> Both macro variants may lead to problems (unwanted results) under certain circumstances. For more detailed information, the following forum thread of &#8222;MS Office 2007 &#8211; Hilfe&#8220; should viewed: <a href=\"http:\/\/www.office2007-hilfe.de\/word-hilfe\/dokumentstruktur-wird-nicht-angezeigt-t5489.html\" target=\"_blank\">Dokumentstruktur wird nicht angezeigt<\/a>\u00a0(only german) (as the website is not available anymore, the link refers to the according website of\u00a0<a href=\"https:\/\/archive.org\">https:\/\/archive.org<\/a>).<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 3 (2010-11-03):<\/strong> <\/span><span style=\"text-decoration: underline;\">The easiest way to avoid the problem completely, is to disable the Navigation Pane during loading of the document.<\/span> Then you can open the document and must wait until Word fully loaded the document (which is not the case, when it appears, it takes a moment longer). After the document has been loaded completely you can activate the Navigation Pane again. Now the document structure in the Navigation Pane should be shown correctly. This approach is in my opinion the easiest and best solution.<br \/>\nIn the forum thread mentioned under Update 2 the following point is addresed: Variant 2 (new version) of the macro changes the the outline level &#8222;without regard to losses.&#8220; If you look at this in the respective option window in Word, you can see that the outline level cannot be changed in any case. This option is blocked (grayed out and not changeable) for standard styles, such as Headings.<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\"><strong>Update 4 (2014-04-03):<\/strong>\u00a0<\/span>English translation of the description added. Source code comments translated to english.<\/p>\n<h1><span style=\"font-size: large;\">Sourcecode<\/span><\/h1>\n<h2><span style=\"font-size: medium;\"><a name=\"src1\"><\/a>Variante 1 (alte Version) \/ Variant 1 (old version)<\/span><\/h2>\n<pre class=\"brush: vb; gutter: true\">Public Sub DokumentenstrukturReparieren()\r\n    &#039; In case of errors goto jump point NoDocumentOpen and end function.\r\n    On Error GoTo NoDocumentOpen\r\n\r\n    &#039; If no file is open, goto jump point NoDocumentOpen and end funtion. The check if a file is open is done with help of the filename length of the active document.\r\n    If Len(ActiveDocument.Name) = 0 Then GoTo NoDocumentOpen\r\n\r\n    Dim bEbene As Byte\r\n    Dim lPos As Long\r\n    Dim bTrackRev As Boolean\r\n    Dim bDocMap As Boolean\r\n\r\n    &#039; Turn of screen updating\r\n    Application.ScreenUpdating = False &#039; Screen updating on (true) or off (false). If screen updating is turned off, all operations, which result in screen updates, should be done faster. Please note that some function do not work correct anymore if the screen updating is turned off (e.g. print). You should always keep in mind that the screen updating needs to be re-enabled if it has been previously disabled.\r\n\r\n    With ActiveWindow\r\n        &#039; safe current state of document structure\r\n        bDocMap = .DocumentMap &#039; The display state of the document structure (shown or hidden) of the active window is safed in bDocMap.\r\n        &#039; Dokumentenstruktur anzeigen\r\n        .DocumentMap = True &#039; With help of ActiveWindow.DocumentMap the display state of the active window can be changed: Shown (true) and Hidden (false).\r\n    End With\r\n\r\n    With ActiveDocument\r\n        &#039; safe current state of revision tracking\r\n        bTrackRev = .TrackRevisions &#039; The current state of the revision tracking of the active window is stored in bTrackRev.\r\n        &#039; Turn off Revision Tracking\r\n        .TrackRevisions = False &#039; With ActiveDocument.TrackRevisions the display state of the revision tracking of the active document can be changed: Shown (true) and hodden (false).\r\n\r\n        With Selection\r\n            &#039; The following searrch is done for outline levels 1 to 9.\r\n            For bEbene = 1 To 9\r\n                &#039; goto beginning of document\r\n                .HomeKey(Unit:=wdStory)\r\n\r\n                &#039; set of search parameters for outline level\r\n                With .Find\r\n                    .ClearFormatting()\r\n                    .Replacement.ClearFormatting()\r\n                    .Text = &quot;&quot;\r\n                    .Replacement.Text = &quot;&quot;\r\n                    .Forward = True\r\n                    .Wrap = wdFindContinue\r\n                    .Format = True\r\n                    .MatchCase = False\r\n                    .MatchWholeWord = False\r\n                    .MatchWildcards = False\r\n                    .MatchSoundsLike = False\r\n                    .MatchAllWordForms = False\r\n                    .ParagraphFormat.OutlineLevel = bEbene\r\n                End With\r\n\r\n                &#039; initialization of search position\r\n                lPos = -1\r\n                &#039; do search for the whole document with all outline levels\r\n                Do While .Find.Execute And .Start &lt;&gt; lPos\r\n                    &#039; Set oultine level to &#039;Body Text&#039;\r\n                    .ParagraphFormat.OutlineLevel = wdOutlineLevelBodyText\r\n                    &#039; update search position\r\n                    lPos = .Start &#039; set current position as new start position.\r\n                    &#039; updated marked area to document area to be searched\r\n                    .Collapse(Direction:=wdCollapseEnd)\r\n                Loop\r\n            Next bEbene\r\n\r\n            &#039; reset oultine level settings of search parameters\r\n            .Find.ParagraphFormat.OutlineLevel = wdOutlineLevelBodyText &#039; set outline level for search to &quot;Body Text&quot;.\r\n        End With\r\n\r\n        &#039; reset state of document structure\r\n        ActiveWindow.DocumentMap = bDocMap\r\n        &#039; reset display state of revision tracking\r\n        .TrackRevisions = bTrackRev\r\n    End With\r\n\r\nNoDocumentOpen:\r\n    &#039; turn on screen updating\r\n    Application.ScreenUpdating = True\r\nEnd Sub<\/pre>\n<h2><span style=\"font-size: medium; line-height: 1.6;\"><a name=\"src2\"><\/a>Variante 2 (neue Version) \/ Variant 2 (new version)<\/span><\/h2>\n<p style=\"text-align: justify;\">Diese L\u00f6sung wurde mir von einem Bekannten\u00a0empfohlen, da sie deutlich schneller ist. Ich konnte zwar selbst noch keine negativen Auswirkungen auf meine Dokumente feststellen, habe diese Variante aber auch noch nicht so ausgiebig getestet.<\/p>\n<p style=\"text-align: justify;\"><strong>English:<\/strong> This solution\u00a0was recommended to me by a friend\u00a0as it is much faster. I could not find any negative effects on my documents, but I did not test this variant extensively.<\/p>\n<pre class=\"brush: vb; gutter: true\">Public Sub DokumentenstrukturReparieren()\r\n    &#039; In case of errors goto jump point NoDocumentOpen and end function.\r\n    On Error GoTo NoDocumentOpen\r\n\r\n    &#039; If no file is open, goto jump point NoDocumentOpen and end funtion. The check if a file is open is done with help of the filename length of the active document.\r\n    If Len(ActiveDocument.Name) = 0 Then GoTo NoDocumentOpen\r\n\r\n    &#039; Turn of screen updating\r\n    Application.ScreenUpdating = False      &#039; Screen updating on (true) or off (false). If screen updating is turned off, all operations, which result in screen updates, should be done faster. Please note that some function do not work correct anymore if the screen updating is turned off (e.g. print). You should always keep in mind that the screen updating needs to be re-enabled if it has been previously disabled.\r\n\r\n    &#039; select complete document\r\n    Selection.WholeStory()\r\n    &#039; Set oultine level to &#039;Body Text&#039;\r\n    Selection.ParagraphFormat.OutlineLevel = wdOutlineLevelBodyText     &#039; Here the oultine level of the selected text will be set to &quot;Body Text&quot;. Outline levels, which are set incorrect (the real problem in case of a wrong document structure in the Navigation Pane), will be treated as normale text. Headings keep the predefined outline levels.\r\n\r\nNoDocumentOpen:\r\n    &#039; turn on screen updating\r\n    Application.ScreenUpdating = True\r\nEnd Sub<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Auch wenn es naheliegend ist mit Hilfe des Inhaltsverzeichnisses durch ein Word-Dokument zu navigieren, falls es denn ein Inhaltsverzeichnis gibt, bietet sich daf\u00fcr doch auch die Dokumentenstruktur an.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,19],"tags":[49,37,38],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-startseite","category-vba-word","tag-programmieren","tag-vba","tag-word"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5LyzC-2i","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=142"}],"version-history":[{"count":20,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":1916,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=\/wp\/v2\/posts\/142\/revisions\/1916"}],"wp:attachment":[{"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kastenmaier.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}