Controlling Excel from Word 2002

E

eltupac

I have been working on this for weeks. I am trying to import a .WRI file
into word, modify it, put it into columns, enter it into an excel file
and save it to .DBF.

I have everything but the parsing of the text in excel. I keep getting
an error. I modified the code found in here, but it crashes at the
"TEXTTOCOLUMNS" line.
This is the code:

Dim i As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add

xlWB.Activate
xlWB.ActiveSheet.Range("A1").Select
xlWB.ActiveSheet.Paste
'xlWB.ActiveSheet.Range("A1").Select
'xlSht.Select "A1"
xlApp.Selection.TextToColumns Destination:=Range("A1").Select,
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(22, 1), Array(32, 1),
Array(44, 1), Array(55, 1), _
Array(61, 1), Array(69, 1), Array(78, 1)),
TrailingMinusNumbers:=True
Columns("A:A").EntireColumn.AutoFit
Columns("A:A").ColumnWidth = 26.14
Columns("B:B").ColumnWidth = 9.57
Columns("C:C").EntireColumn.AutoFit
Columns("C:C").ColumnWidth = 11.71
Columns("D:D").EntireColumn.AutoFit
Columns("D:D").ColumnWidth = 11.14
Columns("H:H").EntireColumn.AutoFit

Thanks for any help
 
E

eltupac

If anyone cares, I have modified and somewhat works now:

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook

xlWB.Activate
xlWB.ActiveSheet.Range("A1").Select
xlWB.ActiveSheet.Paste


With xlWB.ActiveSheet.Columns("A:A")
.TextToColumns DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(22, 1), Array(32, 1),
Array(44, 1), Array(55, 1), _
Array(61, 1), Array(69, 1), Array(78, 1)),
TrailingMinusNumbers:=True
End With

It had to do with the columns....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top