View Single Post
 
Old 04-16-2021, 02:49 PM
Steve Kunkel Steve Kunkel is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: May 2019
Location: Seattle area
Posts: 81
Steve Kunkel is on a distinguished road
Default

I went ahead and put together the kludgy version...

Main code
Code:
Private Sub cmdConvertToText_Click()

On Error GoTo ErrorHandler
    If txtSeparator.Value <> "" Then
       Selection.Tables(1).Select
       Selection.Rows.ConvertToText Separator:="^", NestedTables:=True 'The ^ char is temporary.
       Call DoFindClean("^", (txtSeparator.Value), "0") 'Swap ^ for textbox content.
    Else
        Selection.Rows.ConvertToText Separator:=wdSeparateByDefaultListSeparator, NestedTables:=True
    End If
Exit Sub

ErrorHandler:
   MsgBox "Run Table Converter after clicking in a table.  Don't 'select' the table, just click in it."

End Sub
Function
Code:
Sub DoFindClean(FindText As String, ReplaceText As String, WrapOrNot As String)
  'This module gets called from the Text Cleaner code
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = FindText
        .Replacement.Text = ReplaceText
        .Forward = True
        .Wrap = WrapOrNot
        .MatchWildcards = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Note that the carret "^" is used as a placeholer... If a table happened to have one of those characters already it would mess up my system.
Reply With Quote