R
Ron
Error message "The requested member of the collection does
not exist"
I open a delimited text file, and retrieve data into
variables. For each row from the file I create multiple
tables. After the last table is created (from one row of
data) I print a page break (PROBLEM #1) and continue
printing tables for the next row, etc. PROBLEM #2 -> When
the -second- row is read in from the file, I get the error
message "The requested member of the collection does not
exist" when I try to merge columns in the *first* row of
the *first* table (ie it's not creating a new/different
table for the second row).
So, it looks like I am 1) not creating/selecting area at
the end of the document to put a page-break into, and 2)
not using my Ranges properly. Can anyone see what my
problem is?
Thanks in advance
Ron
'-------------------------------------------------------------
' Opens text file, passes data from each line to ProjectData()
'-------------------------------------------------------------
Public Sub Foo()
Open "C:\Temp\bull_pov.txt" For Input As #1
Set objNewDoc = Documents.Add
Do While Not EOF(1) 'Loop until end of file
' read data from file into the following variables
Input #1, sListedAd, sAddenda, sCntID, .....
ProjectData sListedAt, sAddenda, sCntID, ....
Loop
Close #1
End Sub
'-------------------------------------------------------------
' Prints data into various forms
'-------------------------------------------------------------
Public Sub ProjectData(sListedAt As String, sAddenda As
String, sCntID As String, ....)
Dim objNewDoc As Document
Dim oRange As Range
Set objNewDoc = ActiveDocument
Set oRange = objNewDoc.Range
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Project Number, Location
Dim objProjNumber As Table
Set objProjNumber = objNewDoc.Tables.Add(oRange, 1, 5)
With objProjNumber
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
ERROR ==> .Cell(1, 2).Merge
MergeTo:=objProjNumber.Cell(1, 5)
.Cell(1, 1).Range.Text = sProjectNumber
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Text = sLocation
End With
Set oRange = objNewDoc.Range
oRange.InsertParagraphAfter
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Closing information
Dim objCloseTable As Table
Set objCloseTable = objNewDoc.Tables.Add(oRange, 2, 6)
With objCloseTable
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
.Cell(1, 1).Range.Text = "Other"
.Cell(1, 1).Range.Bold = True
.Cell(1, 3).Range.Text = "Bid Dep."
.Cell(1, 3).Range.Bold = True
.Cell(1, 5).Range.Text = "General"
.Cell(1, 5).Range.Bold = True
.Cell(2, 1).Range.Text = "Closing:"
.Cell(2, 1).Range.Bold = True
.Cell(2, 3).Range.Text = "Closing:"
.Cell(2, 3).Range.Bold = True
.Cell(2, 5).Range.Text = "Closing:"
.Cell(2, 5).Range.Bold = True
End With
' you need an independent Range object
' that starts out with the document's extent(scope)
Set oRange = objNewDoc.Range
' insert a temporary blank paragraph
' to separate the two tables
oRange.InsertParagraphAfter
' put the range at the end of the document
oRange.Collapse direction:=wdCollapseEnd
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
'-------------------------------------------------------------
' Location, Addenda, Comments, Tender Authority
Dim objLACTTable As Table 'L-ocation A-ddenda
C-omments T-ender Auth
Set objLACTTable = objNewDoc.Tables.Add(oRange, 4, 5)
With objLACTTable
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
.Cell(1, 2).Merge
MergeTo:=objLACTTable.Cell(1, 5)
.Cell(1, 1).Range.Text = "Set Location: "
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Text = sLocation
.Cell(2, 2).Merge
MergeTo:=objLACTTable.Cell(2, 5)
.Cell(2, 1).Range.Text = "Addenda: "
.Cell(2, 1).Range.Bold = True
.Cell(2, 2).Range.Text = sAddenda
.Cell(3, 2).Merge
MergeTo:=objLACTTable.Cell(3, 5)
.Cell(3, 1).Range.Text = "Comments: "
.Cell(3, 1).Range.Bold = True
.Cell(3, 2).Range.Text = sComments
.Cell(4, 2).Merge
MergeTo:=objLACTTable.Cell(4, 5)
.Cell(4, 1).Range.Text = "T/A: "
.Cell(4, 1).Range.Bold = True
.Cell(4, 2).Range.Text = "?"
End With
Set oRange = objLACTTable.Range
oRange.InsertParagraphAfter
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Location, Addenda, Comments, Tender Authority
Selection.TypeText Text:=sProjectNumber &
"-------------- @-@ --------------"
Selection.InsertAfter vbFormFeed
Selection.TypeText vbFormFeed
Selection.TypeParagraph
End Sub
not exist"
I open a delimited text file, and retrieve data into
variables. For each row from the file I create multiple
tables. After the last table is created (from one row of
data) I print a page break (PROBLEM #1) and continue
printing tables for the next row, etc. PROBLEM #2 -> When
the -second- row is read in from the file, I get the error
message "The requested member of the collection does not
exist" when I try to merge columns in the *first* row of
the *first* table (ie it's not creating a new/different
table for the second row).
So, it looks like I am 1) not creating/selecting area at
the end of the document to put a page-break into, and 2)
not using my Ranges properly. Can anyone see what my
problem is?
Thanks in advance
Ron
'-------------------------------------------------------------
' Opens text file, passes data from each line to ProjectData()
'-------------------------------------------------------------
Public Sub Foo()
Open "C:\Temp\bull_pov.txt" For Input As #1
Set objNewDoc = Documents.Add
Do While Not EOF(1) 'Loop until end of file
' read data from file into the following variables
Input #1, sListedAd, sAddenda, sCntID, .....
ProjectData sListedAt, sAddenda, sCntID, ....
Loop
Close #1
End Sub
'-------------------------------------------------------------
' Prints data into various forms
'-------------------------------------------------------------
Public Sub ProjectData(sListedAt As String, sAddenda As
String, sCntID As String, ....)
Dim objNewDoc As Document
Dim oRange As Range
Set objNewDoc = ActiveDocument
Set oRange = objNewDoc.Range
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Project Number, Location
Dim objProjNumber As Table
Set objProjNumber = objNewDoc.Tables.Add(oRange, 1, 5)
With objProjNumber
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
ERROR ==> .Cell(1, 2).Merge
MergeTo:=objProjNumber.Cell(1, 5)
.Cell(1, 1).Range.Text = sProjectNumber
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Text = sLocation
End With
Set oRange = objNewDoc.Range
oRange.InsertParagraphAfter
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Closing information
Dim objCloseTable As Table
Set objCloseTable = objNewDoc.Tables.Add(oRange, 2, 6)
With objCloseTable
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
.Cell(1, 1).Range.Text = "Other"
.Cell(1, 1).Range.Bold = True
.Cell(1, 3).Range.Text = "Bid Dep."
.Cell(1, 3).Range.Bold = True
.Cell(1, 5).Range.Text = "General"
.Cell(1, 5).Range.Bold = True
.Cell(2, 1).Range.Text = "Closing:"
.Cell(2, 1).Range.Bold = True
.Cell(2, 3).Range.Text = "Closing:"
.Cell(2, 3).Range.Bold = True
.Cell(2, 5).Range.Text = "Closing:"
.Cell(2, 5).Range.Bold = True
End With
' you need an independent Range object
' that starts out with the document's extent(scope)
Set oRange = objNewDoc.Range
' insert a temporary blank paragraph
' to separate the two tables
oRange.InsertParagraphAfter
' put the range at the end of the document
oRange.Collapse direction:=wdCollapseEnd
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
'-------------------------------------------------------------
' Location, Addenda, Comments, Tender Authority
Dim objLACTTable As Table 'L-ocation A-ddenda
C-omments T-ender Auth
Set objLACTTable = objNewDoc.Tables.Add(oRange, 4, 5)
With objLACTTable
.AutoFormat Format:=wdTableFormatNone
.AutoFormat ApplyBorders:=False
.Cell(1, 2).Merge
MergeTo:=objLACTTable.Cell(1, 5)
.Cell(1, 1).Range.Text = "Set Location: "
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Text = sLocation
.Cell(2, 2).Merge
MergeTo:=objLACTTable.Cell(2, 5)
.Cell(2, 1).Range.Text = "Addenda: "
.Cell(2, 1).Range.Bold = True
.Cell(2, 2).Range.Text = sAddenda
.Cell(3, 2).Merge
MergeTo:=objLACTTable.Cell(3, 5)
.Cell(3, 1).Range.Text = "Comments: "
.Cell(3, 1).Range.Bold = True
.Cell(3, 2).Range.Text = sComments
.Cell(4, 2).Merge
MergeTo:=objLACTTable.Cell(4, 5)
.Cell(4, 1).Range.Text = "T/A: "
.Cell(4, 1).Range.Bold = True
.Cell(4, 2).Range.Text = "?"
End With
Set oRange = objLACTTable.Range
oRange.InsertParagraphAfter
oRange.Collapse direction:=wdCollapseEnd
'-------------------------------------------------------------
' Location, Addenda, Comments, Tender Authority
Selection.TypeText Text:=sProjectNumber &
"-------------- @-@ --------------"
Selection.InsertAfter vbFormFeed
Selection.TypeText vbFormFeed
Selection.TypeParagraph
End Sub