Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing data from word doc to database and test word doc

Status
Not open for further replies.

bplejic

Electrical
May 6, 2008
1
0
0
HR
Hi all,
I'm trying to store scattered text data from several word docs to database MS Access and into test word document but at the end there is no data in database or even in test word document. While Compiling Project I got Compile error Wrong number of arguments or invalid property assigment at line .Cells(.Rows.Count, 1) = sDTE.
Also I would like to save into a MS access table those Strings as Numbers so if You know how.... Thank You very much for any help.
Here is code from macro :

Sub ExtractData2()
Dim sDTE As String
Dim sSubject As String
Dim strFileName As String
Dim strPath As String
Dim FileArray() As String
Dim i As Long
Dim vConnection As ADODB.Connection
Dim vRecordSet As ADODB.Recordset
Dim oDoc As Document
Dim Datadoc As Document
Dim fDialog As FileDialog
Dim Rng As Range
Dim NumRows As Integer
Set vConnection = New ADODB.Connection
Set vRecordSet = New ADODB.Recordset
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
'Pick the folder with the letters
With fDialog
.Title = "Odaberite direktorij s zahtjevima i kliknite na gumb OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
strFileName = Dir$(strPath & "*.doc")
ReDim FileArray(1 To 1000) 'A number larger the expected number of replies
Do While strFileName <> ""
i = i + 1
FileArray(i) = strFileName
'Get the next file name
strFileName = Dir$
Loop
'Resize and preserve the array
ReDim Preserve FileArray(1 To i)
Application.ScreenUpdating = False
'Provide connection string for data using Jet Provider for Access database
vConnection.ConnectionString = "data source=C:\MagRad\Baza.mdb;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open
vRecordSet.Open "MyTable", vConnection, adOpenKeyset, adLockOptimistic
'Retrieve the data
vConnection.Execute "DELETE * FROM MyTable"
'Assign the name of the document to take the data
Set Datadoc = Documents.Open("C:\MagRad\Rez.doc")
'Open the letters in turn
While strFileName <> ""
Set oDoc = Documents.Open(strPath & strFileName)
'Find the DTE text
Set Rng = oDoc.Range
With Rng.Find 'find the first string
.ClearFormatting
Do While .Execute(Findtext:="DTE/*^13", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
'Assign the found text to a variable and
'chop off the last character - '¶'
Rng.SetRange 0, Len(Rng) - 1
sDTE = Rng.Text
Loop
End With
Set Rng = oDoc.Range 'Redefine range after find
With Rng.Find 'find the second string
.ClearFormatting
Do While .Execute(Findtext:="Subject :*^13", _
MatchWildcards:=True, _
Wrap:=wdFindStop, Forward:=True) = True
'Assign the second string to a variable and chop off
'the the leading text and last character.
Rng.SetRange 9, Len(Rng) - 1
sSubject = Rng.Text
Loop
End With
'Switch to the data document and add the content of
'the variables to the blank row of the table
'Datadoc.Activate
Datadoc.Save
If sDTE <> "" Then vRecordSet("DTE") = sDTE
If sSubject <> "" Then vRecordSet("Subject") = sSubject
vRecordSet.Update
With Datadoc.Tables(1).Range
.Rows.Add
.Cells(.Rows.Count, 1) = sDTE
.Cells(.Rows.Count, 2) = sSubject
End With
'Close the letter without saving
oDoc.Close SaveChanges:=wdDoNotSaveChanges
Set oDoc = Nothing
strFileName = Dir$()
Wend
vRecordSet.Close
vConnection.Close
Set vRecordSet = Nothing
Set vConnection = Nothing
Application.ScreenUpdating = True
End Sub
 
Replies continue below

Recommended for you

This question is better answered on Tek-Tips.com... this forum is more about engineering of the languages themselves (contrary to many postings that end up residing here).

Dan - Owner
Footwell%20Animation%20Tiny.gif
 
Status
Not open for further replies.
Back
Top