I can currently get my script to write all highlighted data into a file of my choosing. What I need to do is write it to the word documents existing table. It writes straight over it at the minute and I'm not 100% on how you reference the table you wish to use. My code is below
If anyone can give a little push in the right direction I'd appreciate it!
Code:
Private Sub CommandButton1_Click()
Dim textFile As String, rng As Range, cellValue As Variant, i As Integer, x As Integer
'File to write to that contains table
textFile = Application.DefaultFilePath & "\testFile.doc"
Set rng = Selection
Open textFile For Output As #1
For i = 1 To rng.Rows.Count
For x = 1 To rng.Columns.Count
cellValue = rng.Cells(i, x).Value
If x = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next x
Next i
'Print the contents of cellValue to the immediate window
Debug.Print cellValue
'Ensure file being wrote to is closed
Close #1
'Print a message box to show that it has finished writing the data to the document
MsgBox ("Done")
End Sub
If anyone can give a little push in the right direction I'd appreciate it!