S
sphinney
I'm using Access 2007. I have an issue with the code below. The code is
from the Click event of a button control on a form. Also on the form is a
Bound Object Frame (called Word_bframe) and a Listbox (called TABLES_lbox).
When the user clicks the OPEN button, the code should:
1. Embed the Microsoft Word document designated in the WordDocPath variable
2. Set a reference to the activated Word application
3. Loop through all of the tables in the Word document
4. Select the first cell in each table
5. Add the contents of the first cell to a listbox
Private Sub OPEN_btn_Click()
Dim wrdAPP As Word.Application
Dim wrdDOC As Word.Document
Dim wrdSEL As Word.Selection
Dim wrdTBL As Word.Table
Me![WORD_bframe].OLETypeAllowed = acOLEEmbedded
Me![WORD_bframe].Class = "Word.Document"
Me![WORD_bframe].SourceDoc = WordDocPath
Me![WORD_bframe].SourceItem = ""
Me![WORD_bframe].Action = acOLECreateEmbed
Set wrdAPP = Me![WORD_bframe].Object.Application
Set wrdDOC = wrdAPP.Documents(1)
Set wrdSEL = wrdAPP.Selection
For Each wrdTBL In wrdDOC.Tables
wrdTBL.Cell(1, 1).Select
TABLES_lbox.RowSource = TABLES_lbox.RowSource &
TRIM_CELL(wrdSEL.Text) & ";"
Next wrdTBL
Set wrdSEL = Nothing
Set wrdDOC = Nothing
Set wrdAPP = Nothing
End Sub
The problem arises in the line "wrdTBL.Cell(1, 1).Select". The line does
not produce an error, but it also does not appear to work (i.e. it does not
actually select the cell). When the next line executes it errors because the
wrdSEL object is not defined (because nothing has been selected by the
previous line).
Why wont the "wrdTBL.Cell(1, 1).Select" line work?
Regards,
sphinney
from the Click event of a button control on a form. Also on the form is a
Bound Object Frame (called Word_bframe) and a Listbox (called TABLES_lbox).
When the user clicks the OPEN button, the code should:
1. Embed the Microsoft Word document designated in the WordDocPath variable
2. Set a reference to the activated Word application
3. Loop through all of the tables in the Word document
4. Select the first cell in each table
5. Add the contents of the first cell to a listbox
Private Sub OPEN_btn_Click()
Dim wrdAPP As Word.Application
Dim wrdDOC As Word.Document
Dim wrdSEL As Word.Selection
Dim wrdTBL As Word.Table
Me![WORD_bframe].OLETypeAllowed = acOLEEmbedded
Me![WORD_bframe].Class = "Word.Document"
Me![WORD_bframe].SourceDoc = WordDocPath
Me![WORD_bframe].SourceItem = ""
Me![WORD_bframe].Action = acOLECreateEmbed
Set wrdAPP = Me![WORD_bframe].Object.Application
Set wrdDOC = wrdAPP.Documents(1)
Set wrdSEL = wrdAPP.Selection
For Each wrdTBL In wrdDOC.Tables
wrdTBL.Cell(1, 1).Select
TABLES_lbox.RowSource = TABLES_lbox.RowSource &
TRIM_CELL(wrdSEL.Text) & ";"
Next wrdTBL
Set wrdSEL = Nothing
Set wrdDOC = Nothing
Set wrdAPP = Nothing
End Sub
The problem arises in the line "wrdTBL.Cell(1, 1).Select". The line does
not produce an error, but it also does not appear to work (i.e. it does not
actually select the cell). When the next line executes it errors because the
wrdSEL object is not defined (because nothing has been selected by the
previous line).
Why wont the "wrdTBL.Cell(1, 1).Select" line work?
Regards,
sphinney