Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Storing data from word doc to database and test word doc

 
Logged in as: Guest
arrSession:exec spGetSession 2,7,59539
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Storing data from word doc to database and test word doc
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Storing data from word doc to database and test word doc - 4/27/2008 4:42:10 PM   
  bplejic

 

Posts: 1
Score: 0
Joined: 4/27/2008
Status: offline
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 databse or even in test word document. Macro is connecting to database and opening test word document without problems but somewhere else marco brakes down . Thank You very much for any help.
Here is code from macro :
Sub ExtractData()
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 New ADODB.Connection
Dim vRecordSet As New ADODB.Recordset
Dim oDoc As Word.Document
Dim dataDoc As Document
Dim fDialog As FileDialog
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
Documents.Open ("""C:\MagRad\Rez.doc""")
Set dataDoc = ActiveDocument
'Open the letters in turn
While strFileName <> ""
Set oDoc = Documents.Open(strPath & strFileName)
Selection.HomeKey wdStory 'Start from the top of the letter
With Selection.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 - '¶'
sDTE = Left(Selection.Range, Len(Selection.Range) - 1)
Loop
End With
Selection.HomeKey wdStory 'Start from the top of the letter
With Selection.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 last character and the leading text
sSubject = Mid(Selection.Range, 10, Len(Selection.Range) - 10)
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 Selection
.EndKey wdStory
.MoveUp Unit:=wdLine, Count:=1
.MoveRight Unit:=wdCell, Count:=2 'Add a new blank row
.TypeText Text:=sDTE
.MoveRight Unit:=wdCell
.TypeText Text:=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
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Storing data from word doc to database and test word doc Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts