Importing Text from Word to Access 2003

K

KLegg14534

I am attempting to get information from a Textbox from a MSWord document.
I have gotten as far as being able to open the document I want and selecting
the text box with the information I need. After that, I am unable to get the
data to later insert into the database table.

Please see code below and let me know where I am going wrong or what to do.

Thanks,
Kevin Legg

Public Function GetConfigSheetI()
On Error Resume Next

Dim strTemp As String
Dim objCfgDoc As Object
Dim strDocName As String

Set UnitUnderTest = CurrentDb.OpenRecordset("CurrentUnit")

strFilePath = "G:\Engineering\FACTORY CALIBRATION\"
strDocName = UnitUnderTest![CfgFile] ' "IED509-1626.doc"

Set objCfgDoc = GetObject(FilePath & DocName)
objCfgDoc .Application.Visible = True
objCfgDoc .Shapes("Text Box 82").Select

'************************************
'Everything works up until this point
'************************************

strTemp = objCfgDoc .Shapes("Text Box 82").Selection.WholeStory
objCfgDoc .Shapes("Text Box 82").Selection


Set objCfgDoc = Nothing

End Function
 
H

Hunter57 via AccessMonster.com

Hi,
Does this help?

Shapes can be several different types of objects so it helps to define the
type of Shape, in this case the OLEFormat Object. Shapes can be identified
by index but not by name. OLEFormat Objects can be identified by name. So we
can loop through the shapes setting the OLEFormat Object and then match the
name.

Public Function GetConfigSheetI()
On Error Resume Next

Dim strTemp As String
Dim objCfgDoc As Object
Dim strFilePath As String
Dim strDocName As String
Dim objShape As Object
Dim objOLEShape As Object

Set UnitUnderTest = CurrentDb.OpenRecordset("CurrentUnit")

strFilePath = "G:\Engineering\FACTORY CALIBRATION\"
strDocName = UnitUnderTest![CfgFile] ' "IED509-1626.doc"
Set objCfgDoc = GetObject(strFilePath & strDocName)

For Each objShape In objCfgDoc.Shapes
Set objOLEShape = ilShape.OLEFormat.Object

If objOLEShape.Name = "Text Box 82" Then
strTemp = objOLEShape.Value
Exit For
End If

Next objShape

Set objOLEShape = Nothing
Set objShape = Nothing
Set objCfgDoc = Nothing

End Function

Best Regards
I am attempting to get information from a Textbox from a MSWord document.
I have gotten as far as being able to open the document I want and selecting
the text box with the information I need. After that, I am unable to get the
data to later insert into the database table.

Please see code below and let me know where I am going wrong or what to do.

Thanks,
Kevin Legg

Public Function GetConfigSheetI()
On Error Resume Next

Dim strTemp As String
Dim objCfgDoc As Object
Dim strDocName As String

Set UnitUnderTest = CurrentDb.OpenRecordset("CurrentUnit")

strFilePath = "G:\Engineering\FACTORY CALIBRATION\"
strDocName = UnitUnderTest![CfgFile] ' "IED509-1626.doc"

Set objCfgDoc = GetObject(FilePath & DocName)
objCfgDoc .Application.Visible = True
objCfgDoc .Shapes("Text Box 82").Select

'************************************
'Everything works up until this point
'************************************

strTemp = objCfgDoc .Shapes("Text Box 82").Selection.WholeStory
objCfgDoc .Shapes("Text Box 82").Selection

Set objCfgDoc = Nothing

End Function
 
H

Hunter57 via AccessMonster.com

Pardon me, I had to correct the name of one of the variables.

Public Function GetConfigSheetI()

Dim strTemp As String
Dim objCfgDoc As Object
Dim strFilePath As String
Dim strDocName As String
Dim objShape As Object
Dim objOLEShape As Object

Set UnitUnderTest = CurrentDb.OpenRecordset("CurrentUnit")

strFilePath = "G:\Engineering\FACTORY CALIBRATION\"
strDocName = UnitUnderTest![CfgFile] ' "IED509-1626.doc"
Set objCfgDoc = GetObject(strFilePath & strDocName)

For Each objShape In objCfgDoc.Shapes
Set objOLEShape = objShape.OLEFormat.Object

If objOLEShape.Name = "Text Box 82" Then
strTemp = objOLEShape.Value
Exit For
End If

Next objShape

Set objOLEShape = Nothing
Set objShape = Nothing
Set objCfgDoc = Nothing

End Function
Hi,
Does this help?

Shapes can be several different types of objects so it helps to define the
type of Shape, in this case the OLEFormat Object. Shapes can be identified
by index but not by name. OLEFormat Objects can be identified by name. So we
can loop through the shapes setting the OLEFormat Object and then match the
name.

Public Function GetConfigSheetI()
On Error Resume Next

Dim strTemp As String
Dim objCfgDoc As Object
Dim strFilePath As String
Dim strDocName As String
Dim objShape As Object
Dim objOLEShape As Object

Set UnitUnderTest = CurrentDb.OpenRecordset("CurrentUnit")

strFilePath = "G:\Engineering\FACTORY CALIBRATION\"
strDocName = UnitUnderTest![CfgFile] ' "IED509-1626.doc"
Set objCfgDoc = GetObject(strFilePath & strDocName)

For Each objShape In objCfgDoc.Shapes
Set objOLEShape = ilShape.OLEFormat.Object

If objOLEShape.Name = "Text Box 82" Then
strTemp = objOLEShape.Value
Exit For
End If

Next objShape

Set objOLEShape = Nothing
Set objShape = Nothing
Set objCfgDoc = Nothing

End Function

Best Regards
I am attempting to get information from a Textbox from a MSWord document.
I have gotten as far as being able to open the document I want and selecting
[quoted text clipped - 32 lines]
End Function
 

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