Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PA PA is offline
external usenet poster
 
Posts: 101
Default Importing to Excel 2003 - Code from Jean-Yves

I found the below code in this group, provided by Jean-Yves. The OP was
someone named Pepper.
It is to import a series of tables from MS Word files, starting with the
second row of the table, into Excel. I have a similar task to perform. I
tried this and was getting a Compile error at the second line,

Dim wdApp As Word.Application

The error is User-defined type not defined
I couldnt get past this.
Furthermore, there is a single line in each of the Word files, above the
tables, that I need to imported as well, and would be most suitable if this
line went into column A, to the left of the first imported row from each of
the Word
tables, which would start in Column B of the destination Excel file. I hope
I explained the adequately to be understood. The code follows:


Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Importing to Excel 2003 - Code from Jean-Yves

You are missing the Reference to Microsoft word in VBA

Tools - References then locate Microsoft Word Object and check box then
press OK. Chosse the latest version of the word object on your computer.

"PA" wrote:

I found the below code in this group, provided by Jean-Yves. The OP was
someone named Pepper.
It is to import a series of tables from MS Word files, starting with the
second row of the table, into Excel. I have a similar task to perform. I
tried this and was getting a Compile error at the second line,

Dim wdApp As Word.Application

The error is User-defined type not defined
I couldnt get past this.
Furthermore, there is a single line in each of the Word files, above the
tables, that I need to imported as well, and would be most suitable if this
line went into column A, to the left of the first imported row from each of
the Word
tables, which would start in Column B of the destination Excel file. I hope
I explained the adequately to be understood. The code follows:


Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
PA PA is offline
external usenet poster
 
Posts: 101
Default Importing to Excel 2003 - Code from Jean-Yves

Thanks for the tip, I am having my Desktop software group fix the Word Object
Library issue. It is missing. Large companies equals long waits for
seemingly easy to address issues.
In the meantime, if I have a line of text above my tables, in each file and
I would like to have it imported into Column A, for each word file, lined up
with the first row of the imported table starting in Column B, how would I
amend the code?
Thank you very, very much.

"Joel" wrote:

You are missing the Reference to Microsoft word in VBA

Tools - References then locate Microsoft Word Object and check box then
press OK. Chosse the latest version of the word object on your computer.

"PA" wrote:

I found the below code in this group, provided by Jean-Yves. The OP was
someone named Pepper.
It is to import a series of tables from MS Word files, starting with the
second row of the table, into Excel. I have a similar task to perform. I
tried this and was getting a Compile error at the second line,

Dim wdApp As Word.Application

The error is User-defined type not defined
I couldnt get past this.
Furthermore, there is a single line in each of the Word files, above the
tables, that I need to imported as well, and would be most suitable if this
line went into column A, to the left of the first imported row from each of
the Word
tables, which would start in Column B of the destination Excel file. I hope
I explained the adequately to be understood. The code follows:


Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Importing to Excel 2003 - Code from Jean-Yves

Try these changes

Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String
Dim MyRange As Word.Range

Set TSheet = ActiveWorkbook.ActiveSheet

Set wdApp = New Word.Application
'initialise counter
RowCount = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename)

With wdDoc
temp = .Tables(1).Cell(2, 1).Range.Text 'read word cell
TSheet.Range("B" & RowCount) = temp
temp = .Tables(1).Cell(2, 2).Range.Text 'read word cell
TSheet.Range("C" & RowCount) = temp

'etc
Set MyRange = .Tables(1).Range
With MyRange
.Start = .Start - 1
.Collapse wdCollapseStart
.Move wdSentence, -1
MySentence = .Sentences(1)
TSheet.Range("A" & RowCount) = MySentence
End With
End With

wdDoc.Close
RowCount = RowCount + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub


"PA" wrote:

Thanks for the tip, I am having my Desktop software group fix the Word Object
Library issue. It is missing. Large companies equals long waits for
seemingly easy to address issues.
In the meantime, if I have a line of text above my tables, in each file and
I would like to have it imported into Column A, for each word file, lined up
with the first row of the imported table starting in Column B, how would I
amend the code?
Thank you very, very much.

"Joel" wrote:

You are missing the Reference to Microsoft word in VBA

Tools - References then locate Microsoft Word Object and check box then
press OK. Chosse the latest version of the word object on your computer.

"PA" wrote:

I found the below code in this group, provided by Jean-Yves. The OP was
someone named Pepper.
It is to import a series of tables from MS Word files, starting with the
second row of the table, into Excel. I have a similar task to perform. I
tried this and was getting a Compile error at the second line,

Dim wdApp As Word.Application

The error is User-defined type not defined
I couldnt get past this.
Furthermore, there is a single line in each of the Word files, above the
tables, that I need to imported as well, and would be most suitable if this
line went into column A, to the left of the first imported row from each of
the Word
tables, which would start in Column B of the destination Excel file. I hope
I explained the adequately to be understood. The code follows:


Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename < ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing/linking data from an Access 2003 Query to an Excel 2003 PerryK Excel Discussion (Misc queries) 2 August 24th 09 07:06 PM
Importing Alan Beban's code on Arrays; Importing a module or a project Steve G Excel Worksheet Functions 4 August 27th 07 04:18 PM
Importing XML into Excel 2003 from a URL BigAndy[_2_] Excel Programming 1 March 22nd 07 12:03 PM
Jean-Guy question Shu of AZ Excel Discussion (Misc queries) 2 December 19th 06 05:27 PM
Importing data from Access to Excel 2003 using code Nagesh Excel Programming 3 December 27th 05 02:15 PM


All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"