D
doctorjones_md
Jezebel,
Thank you for all your help. I've been able in incorporate your code into
my project, but I seem to be getting the following error message when I run
it:
"Run-time error 4605" This method or property is not available because no
text is selected
When I get the error message, if I choose debug, the following line is
highlighted:
pRange.Copy
If I Reset press the Reset button in the menu bar of VBE, then the data from
the seleted Row is inserted into Document1
I get the error message when I run routine #1 below, but not when I run
routine #2 (see below)
Could you please tell me how I can resolve this issue? Here is the code
I'm using:
#1 'Code for frmProducts:
Option Explicit
Dim pTable1 As Table
Dim pTable2 As Table
Dim pIndex As Long
Dim pRange As Word.Range
Dim ExportDoc As Word.Document '**** NOTE -- I set these dimensions
outside for the Sub (as in your example) so I could use it for several
subs/options on the form
Private Sub cbxLinen_Click()
Set ExportDoc = Documents.Open("E:\Products\Linen.doc") '*** This Opens
the file Linen.doc as ExportDoc Projects -- How do write the code to close
ExportDoc after the data has been inserted into Document1?****
Set pTable1 = ExportDoc.Tables(1)
Set pTable2 = Documents("Document1").Tables(12) '**** I want the data
from ExportDoc.Tables(1) to be inserted into Table 12 of Document1
If Me.cbxLinen.Value = True Then
Me.cbxNotIncluded.Value = False '***** This is the default value of
frmProducts
pTable1.Rows.Add BeforeRow:=pTable2.Rows(3) 'Adds a NEW row in the
destination table -- active document
For pIndex = 1 To pTable1.Columns.Count
Set pRange = pTable1.Cell(7, pIndex).Range 'The row in the Table you
want to import
pRange.End = pRange.End - 1
pRange.Copy '**** This is the line that's highlighted during debug
pTable2.Cell(3, pIndex).Range.Paste
Next
Me.cmdOK.Enabled = True
End If
Set ExportDoc = Nothing '**** I thought this might close ExportDoc, but it
does nothing -- any thoughts?
End Sub
==============================================
BUT -- everything works fine on this form (with identical code) -- EXCEPT
that the file ExportDoc doesn't close after copying the Rows to Document1
==============================================
#2 'Code for frmServices:
Option Explicit
Dim pTable1 As Table
Dim pTable2 As Table
Dim pIndex As Long
Dim pRange As Word.Range
Dim ExportDoc As Word.Document
Private Sub cbxDelivery_Click()
Set ExportDoc = Documents.Open("H:\Services\Delivery.doc")
Set pTable1 = ExportDoc.Tables(1)
Set pTable2 = Documents("Document1").Tables(8) 'Sets Table 8 as the
insertion point
If Me.cbxMS_IDE.Value = True Then
pTable1.Rows.Add BeforeRow:=pTable2.Rows(3) 'Sets the insertion
point before Row 3
For pIndex = 1 To pTable1.Columns.Count
Set pRange = pTable1.Cell(2, pIndex).Range 'Selects Row 2 in
ExportDoc
pRange.End = pRange.End - 1
pRange.Copy
pTable2.Cell(3, pIndex).Range.Paste 'Pastes data in Row 3 of Table 8
in Document1
Next
Me.cmdOK.Enabled = True
End If
Set ExportDoc = Nothing
End Sub
Much Thanks in Advance
Shane
Thank you for all your help. I've been able in incorporate your code into
my project, but I seem to be getting the following error message when I run
it:
"Run-time error 4605" This method or property is not available because no
text is selected
When I get the error message, if I choose debug, the following line is
highlighted:
pRange.Copy
If I Reset press the Reset button in the menu bar of VBE, then the data from
the seleted Row is inserted into Document1
I get the error message when I run routine #1 below, but not when I run
routine #2 (see below)
Could you please tell me how I can resolve this issue? Here is the code
I'm using:
#1 'Code for frmProducts:
Option Explicit
Dim pTable1 As Table
Dim pTable2 As Table
Dim pIndex As Long
Dim pRange As Word.Range
Dim ExportDoc As Word.Document '**** NOTE -- I set these dimensions
outside for the Sub (as in your example) so I could use it for several
subs/options on the form
Private Sub cbxLinen_Click()
Set ExportDoc = Documents.Open("E:\Products\Linen.doc") '*** This Opens
the file Linen.doc as ExportDoc Projects -- How do write the code to close
ExportDoc after the data has been inserted into Document1?****
Set pTable1 = ExportDoc.Tables(1)
Set pTable2 = Documents("Document1").Tables(12) '**** I want the data
from ExportDoc.Tables(1) to be inserted into Table 12 of Document1
If Me.cbxLinen.Value = True Then
Me.cbxNotIncluded.Value = False '***** This is the default value of
frmProducts
pTable1.Rows.Add BeforeRow:=pTable2.Rows(3) 'Adds a NEW row in the
destination table -- active document
For pIndex = 1 To pTable1.Columns.Count
Set pRange = pTable1.Cell(7, pIndex).Range 'The row in the Table you
want to import
pRange.End = pRange.End - 1
pRange.Copy '**** This is the line that's highlighted during debug
pTable2.Cell(3, pIndex).Range.Paste
Next
Me.cmdOK.Enabled = True
End If
Set ExportDoc = Nothing '**** I thought this might close ExportDoc, but it
does nothing -- any thoughts?
End Sub
==============================================
BUT -- everything works fine on this form (with identical code) -- EXCEPT
that the file ExportDoc doesn't close after copying the Rows to Document1
==============================================
#2 'Code for frmServices:
Option Explicit
Dim pTable1 As Table
Dim pTable2 As Table
Dim pIndex As Long
Dim pRange As Word.Range
Dim ExportDoc As Word.Document
Private Sub cbxDelivery_Click()
Set ExportDoc = Documents.Open("H:\Services\Delivery.doc")
Set pTable1 = ExportDoc.Tables(1)
Set pTable2 = Documents("Document1").Tables(8) 'Sets Table 8 as the
insertion point
If Me.cbxMS_IDE.Value = True Then
pTable1.Rows.Add BeforeRow:=pTable2.Rows(3) 'Sets the insertion
point before Row 3
For pIndex = 1 To pTable1.Columns.Count
Set pRange = pTable1.Cell(2, pIndex).Range 'Selects Row 2 in
ExportDoc
pRange.End = pRange.End - 1
pRange.Copy
pTable2.Cell(3, pIndex).Range.Paste 'Pastes data in Row 3 of Table 8
in Document1
Next
Me.cmdOK.Enabled = True
End If
Set ExportDoc = Nothing
End Sub
Much Thanks in Advance
Shane