Hello,
I have a following format of text in a document - the text in a bookmark icludes a paragraph break:
HEADING STYLE 1¶
[Text in a bookmark in Normal Style¶]
HEADING STYLE 2¶
What I'd like to do is to insert a paragraph break just after the bookmark as the text inside will be replaced:
HEADING STYLE 1¶
[Text in a bookmark in Normal Style¶]
¶ (Normal Style required)
HEADING STYLE 2¶
I have a code but the result is following:
HEADING STYLE 1¶
[Text in a bookmark in Normal Style¶]
HEADING STYLE 2¶ (just the numbering)
Remaing part of the HEADING STYLE 2 line in Normal Style¶
Can someone help me with a solution? Thank you.
Option Explicit
Sub Insert_Line_after_Bookmark()
Application.ScreenUpdating = False
Dim strFolder As String
Dim strFile As String
Dim strName As String
Dim wdDoc As Document
Dim i As Long
Dim oRng As Range
Dim BkMks As Bookmark
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
wdDoc.Activate
With wdDoc
For i = 1 To ActiveDocument.Bookmarks.Count
strName = ActiveDocument.Bookmarks(i).Name
wdDoc.Bookmarks(strName).Select
wdDoc.Range(Selection.End, Selection.End).Select
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Normal")
Next i
End With
wdDoc.Close SaveChanges:=True
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = False
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function