View Single Post
 
Old 11-13-2022, 10:04 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I assume that you want to run this macro from Excel. The string here, to be replaced by your variable is sList. The macro opens a Word document and creates a one column table that contains the list, which I think is what you are trying to achieve. You can integrate this with your existing menu.

Code:
Sub Macro1()
Dim wdApp As Object
Dim oDoc As Object
Dim oTable As Object
Dim sList As String
Dim vList As Variant
Dim oRng As Object
Dim i As Integer
Dim iRow As Object
    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    sList = "This is; a test, of a string" 'the variable
    sList = Replace(sList, ";", ",")
    Set oDoc = wdApp.Documents.Add
    Set oRng = oDoc.Range
    oRng.Collapse 0
    Set oTable = oDoc.Tables.Add(oRng, 1, 1)
    vList = Split(sList, ",")
    oTable.Cell(1, 1).Range.Text = Trim(vList(0))
    For i = 1 To UBound(vList)
        Set iRow = oTable.Rows.Add
        oTable.Cell(iRow.Index, 1).Range.Text = Trim(CStr(vList(i)))
    Next i
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote