Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-20-2023, 06:37 AM
dopey dopey is offline Combining more than one line of the same item into one line Windows 10 Combining more than one line of the same item into one line Office 2021
Novice
Combining more than one line of the same item into one line
 
Join Date: Feb 2023
Posts: 5
dopey is on a distinguished road
Default

Hi Andrew, thanks so much for the reply. Unfortunately, this saved an empty file.

This is my full code (with your addition):

Code:
Sub List()

    Dim oDoc As Document, oTarget As Document
    Dim oRng As Range, oPara As Range
    Set oDoc = ActiveDocument
    Set oTarget = Documents.Add
    Set oRng = oDoc.Range
    
    Dim str As String, arr() As String, i As Integer
    Set oRng = ActiveDocument.Range
    With oRng.Find
      Do While .Execute(findText:="#")
        arr = Split(oRng.Paragraphs(1).Range.Text, "#")
        For i = 1 To UBound(arr)
          str = str & arr(0) & vbCr
        Next i
       Set oRng = oRng.Paragraphs(1).Range
       oRng.Collapse Direction:=wdCollapseEnd
       oRng.End = ActiveDocument.Range.End
      Loop
    End With
    Debug.Print str
    
    Set oDoc = Nothing
    Set oTarget = Nothing
    Set oRng = Nothing
    Set oPara = Nothing
    
    Dim DateStr, FileStr As String
    DateStr = Format(CStr(Now), "yyyy-mm-dd hh mm")
    FileStr = "List " & DateStr & ".docx"

        ChangeFileOpenDirectory "C:\Users\dopey\Documents\List\"
        ActiveDocument.SaveAs2 FileName:=FileStr, FileFormat:= _
        wdFormatXMLDocument
        ActiveDocument.Close
        Windows("List.docx").Activate

Dim intResponse As Integer
 
intResponse = _
 MsgBox("Do you want to save all documents?", vbYesNo)
 If intResponse = vbYes Then Application.Quit _
 SaveChanges:=wdSaveChanges, OriginalFormat:=wdWordDocument

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
1st line of 4-line poem centrally aligned; how to get lines 2-4 to start at same location on page Swarup Word 6 09-16-2022 11:07 AM
Combining more than one line of the same item into one line Making mail merge blank fill a line to highlight that line rgm60527 Mail Merge 2 02-22-2022 11:13 AM
Combining more than one line of the same item into one line word erases line bottom in tight line spacing when new line is added ozzzy Word 2 01-21-2021 06:41 AM
Usability of space between final line of body text and footnote separator line Swarup Word 6 07-28-2018 12:51 PM
Combining IMAP inbox and sent item folders kenelder Outlook 1 07-17-2015 02:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft