dj44
03-25-2016, 03:26 PM
Folks,
Good day and evening to all.:)
I am needing some help on my table task.
I am trying to import the text found in word documents. These documents have various descriptions of data that I need to organise.
- 1 word document into 1 table cell in column 2.
I am hoping I can keep the source document formatting too - it was nicely formatted in the document.
Example:
Column 2
==================
Content of File1.docx
==================
Content of File 2.docx
==================
Content of File 3.docx
==================
I have got started but its gone wrong. I don't know what i did wrong - actually there is a lot that's gone wrong - but i'm not sure how to explain.
Sub ImportWordDocumentIntoTableCell()
' import my files into a table -
' 1 file goes into 1 table cell in column 2
Application.ScreenUpdating = False
Dim strFolder As String
Dim strFile As String
Dim wdDoc As Document
Dim oTable As Table
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdDocTmp = Documents.Add
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
i = 0
Set wdDoc = Documents.Add
With wdDoc
On Error Resume Next
Set oTable = ActiveDocument.Tables(1)
'Start of loop
For i = 2 To oTable.Rows.Count
'Put Each File into the table cell in column 2
strFile.Import strFolder & "\" & strFile = oTable.Cell(i, 2).Range ' This is wrong
On Error GoTo 0
End With
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String ' To browse for the folder that has the word documents
End Function
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
Now i have been searching googles brains for articles on this but i cant find anything to help me get it started up
If you can assist on this poorly code I will be grateful.
Thank you for your expert time and advice.
cheers:)
DJ
Good day and evening to all.:)
I am needing some help on my table task.
I am trying to import the text found in word documents. These documents have various descriptions of data that I need to organise.
- 1 word document into 1 table cell in column 2.
I am hoping I can keep the source document formatting too - it was nicely formatted in the document.
Example:
Column 2
==================
Content of File1.docx
==================
Content of File 2.docx
==================
Content of File 3.docx
==================
I have got started but its gone wrong. I don't know what i did wrong - actually there is a lot that's gone wrong - but i'm not sure how to explain.
Sub ImportWordDocumentIntoTableCell()
' import my files into a table -
' 1 file goes into 1 table cell in column 2
Application.ScreenUpdating = False
Dim strFolder As String
Dim strFile As String
Dim wdDoc As Document
Dim oTable As Table
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdDocTmp = Documents.Add
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
i = 0
Set wdDoc = Documents.Add
With wdDoc
On Error Resume Next
Set oTable = ActiveDocument.Tables(1)
'Start of loop
For i = 2 To oTable.Rows.Count
'Put Each File into the table cell in column 2
strFile.Import strFolder & "\" & strFile = oTable.Cell(i, 2).Range ' This is wrong
On Error GoTo 0
End With
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String ' To browse for the folder that has the word documents
End Function
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
Now i have been searching googles brains for articles on this but i cant find anything to help me get it started up
If you can assist on this poorly code I will be grateful.
Thank you for your expert time and advice.
cheers:)
DJ