R
Ron
Hi
I want to create tables and populate them with values I
retrieve from a text file. Basically, I get a lot of data
from one row in the file, create multiple tables, get the
next row and create the same tables over and over again,
until there is no more data available. I can create a
table, populate it with data, but am unable to get out of
the table and create another one directly after it
(underneath it). I get the error:
The range cannot be deleted
It works fine if I create a table, insert values/text into
a cell, move right, enter data, ....(see 2nd code snippet
below) but the code isn't as clear or as easy to maintain.
I've seen others with this error message (googled), but
didn't come across a solution which would fix my problem.
Here's part of my code that doesn't work:
------------- WHAT I WANT ------------------------
Do While Not EOF(1) 'Loop until end of file
Dim objTable As Table
Dim objCloseTable As Table
Set objCloseTable =
objNewDoc.Tables.Add(objNewDoc.Range, 2, 6)
objCloseTable.Cell(1, 1).Range.Text = "Other"
objCloseTable.Cell(1, 3).Range.Text = "Bid Dep."
objCloseTable.Cell(1, 5).Range.Text = "General"
objCloseTable.Cell(2, 1).Range.Text = "Closing:"
objCloseTable.Cell(2, 3).Range.Text = "Closing:"
objCloseTable.Cell(2, 5).Range.Text = "Closing:"
' read data from file into the following variables
Input #1, sListedAd, sAddenda, sCntID, sLocation, '...
objCloseTable.Cell(1, 2).Range.Text = sOtherClosingDate
objCloseTable.Cell(1, 4).Range.Text = sBidClosingDate
objCloseTable.Cell(1, 6).Range.Text = sGeneralClosingTime
objCloseTable.Cell(2, 2).Range.Text = sOtherClosingLocation
objCloseTable.Cell(2, 4).Range.Text = sBidClosingLocation
objCloseTable.Cell(2, 6).Range.Text = GeneralClosingLocation
Dim objLocTable As Table
Set objLocTable = objNewDoc.Tables.Add(objNewDoc.Range,
1, 2) '*ERROR
objLocTable .Cell(1, 1).Range.Text = "Location"
objLocTable .Cell(1, 2).Range.Text = sComments
Loop
------------- /WHAT I WANT ------------------------
Here's part of my code that works:
------------- WHAT I HAVE------------------------
'--- Closing Dates and Locations ---
ActiveDocument.Tables.Add Range:=Selection.Range,
NumRows:=2, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="Other"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sOtherClosingDate & " " &
sOtherClosingTime
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Bid"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sBidClosingDate & " " &
sBidClosingTime
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="General"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sClosingDate & " " &
sGeneralClosingTime
Selection.TypeText Text:=sOtherClosingLocation
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="-"
------------- /WHAT I HAVE------------------------
I much prefer the first type of sample data above. Any
ideas on how I can get out of the table (from first example
above?), which I believe is the problem?
TIA
Ron
I want to create tables and populate them with values I
retrieve from a text file. Basically, I get a lot of data
from one row in the file, create multiple tables, get the
next row and create the same tables over and over again,
until there is no more data available. I can create a
table, populate it with data, but am unable to get out of
the table and create another one directly after it
(underneath it). I get the error:
The range cannot be deleted
It works fine if I create a table, insert values/text into
a cell, move right, enter data, ....(see 2nd code snippet
below) but the code isn't as clear or as easy to maintain.
I've seen others with this error message (googled), but
didn't come across a solution which would fix my problem.
Here's part of my code that doesn't work:
------------- WHAT I WANT ------------------------
Do While Not EOF(1) 'Loop until end of file
Dim objTable As Table
Dim objCloseTable As Table
Set objCloseTable =
objNewDoc.Tables.Add(objNewDoc.Range, 2, 6)
objCloseTable.Cell(1, 1).Range.Text = "Other"
objCloseTable.Cell(1, 3).Range.Text = "Bid Dep."
objCloseTable.Cell(1, 5).Range.Text = "General"
objCloseTable.Cell(2, 1).Range.Text = "Closing:"
objCloseTable.Cell(2, 3).Range.Text = "Closing:"
objCloseTable.Cell(2, 5).Range.Text = "Closing:"
' read data from file into the following variables
Input #1, sListedAd, sAddenda, sCntID, sLocation, '...
objCloseTable.Cell(1, 2).Range.Text = sOtherClosingDate
objCloseTable.Cell(1, 4).Range.Text = sBidClosingDate
objCloseTable.Cell(1, 6).Range.Text = sGeneralClosingTime
objCloseTable.Cell(2, 2).Range.Text = sOtherClosingLocation
objCloseTable.Cell(2, 4).Range.Text = sBidClosingLocation
objCloseTable.Cell(2, 6).Range.Text = GeneralClosingLocation
Dim objLocTable As Table
Set objLocTable = objNewDoc.Tables.Add(objNewDoc.Range,
1, 2) '*ERROR
objLocTable .Cell(1, 1).Range.Text = "Location"
objLocTable .Cell(1, 2).Range.Text = sComments
Loop
------------- /WHAT I WANT ------------------------
Here's part of my code that works:
------------- WHAT I HAVE------------------------
'--- Closing Dates and Locations ---
ActiveDocument.Tables.Add Range:=Selection.Range,
NumRows:=2, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="Other"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sOtherClosingDate & " " &
sOtherClosingTime
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Bid"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sBidClosingDate & " " &
sBidClosingTime
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="General"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:=sClosingDate & " " &
sGeneralClosingTime
Selection.TypeText Text:=sOtherClosingLocation
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="-"
------------- /WHAT I HAVE------------------------
I much prefer the first type of sample data above. Any
ideas on how I can get out of the table (from first example
above?), which I believe is the problem?
TIA
Ron