gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 351
- Office Version
- 365
- Platform
- Windows
- Mobile
Sorry for the double-post, but I used the wrong title in my last post.
A table like this exists in a Word document:
Currently, the code I'm using to import the table's data will put the data with more than one value (under Toll Booths and Toll) into the same cell. I don't want to copy and paste the table, and I don't need to preserve the bullets. I just need to put the separate values in separate cells.
Code (omits calling sub):
A table like this exists in a Word document:
Currently, the code I'm using to import the table's data will put the data with more than one value (under Toll Booths and Toll) into the same cell. I don't want to copy and paste the table, and I don't need to preserve the bullets. I just need to put the separate values in separate cells.
Code (omits calling sub):
VBA Code:
Sub WordInterop(ByVal wksMain As Worksheet, ByRef strFolder As String)
Dim fso As FileSystemObject
Dim aFold As Folder
Dim aFile As File
Dim wordApp As Word.Application
Dim wordFile As Word.Document
Dim wordTable As Word.Table
Dim wordTableCell As Word.Cell
Dim rngImport As Excel.Range
Dim i As Long, rowNoOutput As Long
Dim rowNo As Long, colNo As Long
Dim headersCount As Long
Dim strImport As String, tblHeaders As String
Set wordApp = New Word.Application
Set rngImport = wksMain.Range("A1")
Set fso = New FileSystemObject
Set aFold = fso.GetFolder(strFolder)
rowNoOutput = 1
headersCount = 0
tblHeaders = "City Section Toll Booths Toll"
wordApp.Visible = False
For Each aFile In aFold.Files
If (Not InStr(1, aFile, "~") > 0 And InStr(1, aFile.Name, ".doc") > 0) Then
Set wordFile = wordApp.Documents.Open(aFold.Path & Application.PathSeparator & aFile.Name)
For i = 0 To wordFile.Tables.Count - 1
With wordFile.Tables(i + 1)
For rowNo = 0 To .Rows.Count - 1
For colNo = 0 To .Columns.Count - 1
strImport = WorksheetFunction.Clean( _
.Cell(rowNo + 1, colNo + 1).Range.Text)