Jane Doe Start Finish
It's usually a field list I dumped from SQL Server and I need to drop it in as cells in spreadsheet
here's the VBA script I used to do this:
In a Word VBA Module (usualy a module for tools in the 'Normal.dot' file)
Public Sub ReplaceSpacesWithTabs()
Dim slct As Selection 'current selection
Dim s As String 'string to manipulate
Dim i As Integer 'counter
'set selection to current selection
Set slct = ActiveDocument.ActiveWindow.Selection
'set string to manipulate
s = slct.Text
'loop through string replacing two spaces with one
'and do this as long as there are two spaces in the string
Do
i = Len(s)'measure string
s = Replace(s, " ", " ")
Loop While i <> Len(s)
'replace the single spaces with tabs 'chr(9)'
s = Replace(s, " ", Chr(9)) '9 = tab character
'reset the selection text with the tabbed text
slct.Text = s
End Sub
I copy and paste the field list and dump it in Word, select all, and then run the script (via a tool bar button.)
No comments:
Post a Comment