I have a word document that I want to convert/copy to excel. It is a table which is 3 boxes wide with name in box 1, address in box 2 and details in box 3. How do I do this so it is the same in excel. If I copy and paste it puts the address in different cells when I want it in one cell. I hope I have explained ok.
Sub ImportWordTable() Dim wdDoc As Object Dim wdFileName As Variant Dim TableNo As Integer 'table number in Word Dim iRow As Long 'row index in Excel Dim iCol As Integer 'column index in Excel wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _ "Browse for file containing table to be imported") If wdFileName = False Then Exit Sub '(user cancelled import file browser) Set wdDoc = GetObject(wdFileName) 'open Word file With wdDoc TableNo = wdDoc.tables.Count If TableNo = 0 Then MsgBox "This document contains no tables", _ vbExclamation, "Import Word Table" ElseIf TableNo > 1 Then TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _ "Enter table number of table to import", "Import Word Table", "1") End If With .tables(TableNo) 'copy cell contents from Word table cells to Excel cells For iRow = 1 To .Rows.Count For iCol = 1 To .Columns.Count Cells(iRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text) Next iCol Next iRow End With End With Set wdDoc = Nothing End Sub
To use this, open a blank Excel workbook. ALT + F11 to open the Visual Basic Editor. Insert|Module and paste in the code above. Close the VBE. Go to a blank worksheet, Tools > Macros > Macro, click ImportWordTable and click the Run button.
That kind of worked! When I run macro it said there 2 tables to insert and asked which one to import. It had 1 selected as default which I selected but box 2 and 3 were merged together. Box 1 was fine with the names in.