Read Multiple files in Vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siddhi
    New Member
    • Jul 2006
    • 3

    Read Multiple files in Vb6

    Hi, I am very very new to vb6. I am trying to browse and read multiple microsoft word files. i am able to do for one file as follow, but not multiple files. Please I need help ASAP. Thanks

    Private Sub Process()
    On Error GoTo Err_Handle
    Dim i As Double
    Dim SRSWordStr As String
    Dim newStart As Double
    Dim tmpStrStart As Double
    Dim tmpStrEnd As Double
    Dim StopFinding As Boolean
    Dim OneSRSTagInfo As String
    Set SRSWordApp = New Word.Applicatio n
    Set SRDDWordApp = New Word.Applicatio n
    SRSWordApp.Docu ments.Open CStr(txtSRSF)
    SRDDWordApp.Doc uments.Open CStr(txtSRDDF)
    CreateExcelFile
    SRSWordApp.Sele ction.WholeStor y
    SRSWordApp.Sele ction.Copy
    SRDDWordApp.Sel ection.WholeSto ry
    SRDDWordApp.Sel ection.Copy
    'MsgBox SRSWordApp.Sele ction.Text
    SRSWordStr = SRSWordApp.Sele ction.Text
    SRDDWordStr = SRDDWordApp.Sel ection.Text
    rw = 2
    newStart = 1
    While StopFinding = False
    If newStart = 0 Then
    GoTo LBLSAVE_FILES
    End If
    If InStr(newStart, SRSWordStr, "[") > 0 Then
    For i = newStart To Len(SRSWordStr)
    If Mid(SRSWordStr, i, 1) = "[" Then
    tmpStrStart = i
    tmpStrEnd = Val(InStr(i + 1, SRSWordStr, "[") - 1)
    If tmpStrEnd = -1 Then
    newStart = 0
    StopFinding = False
    OneSRSTagInfo = Mid(SRSWordStr, tmpStrStart)
    Else
    newStart = tmpStrEnd + 1
    OneSRSTagInfo = Mid(SRSWordStr, tmpStrStart, Val(tmpStrEnd) - Val(tmpStrStart ))
    End If
    TransferToExcel (OneSRSTagInfo)
    rw = rw + 1
    End If
    Next
    Else
    StopFinding = True
    End If
    Wend
    LBLSAVE_FILES:

    Columns("A:D"). EntireColumn.Au toFit
    xlFile.Range("A 1:D" & rw).BorderAroun d 1
    xlFile.ActiveWo rkbook.SaveAs txtXl
    xlFile.ActiveWo rkbook.Close
    SRSWordApp.Acti veDocument.Clos e
    SRDDWordApp.Act iveDocument.Clo se
    SRSWordApp.Quit
    SRDDWordApp.Qui t
    xlFile.Quit
    Set SRDDWordApp = Nothing
    Set SRSSWordApp = Nothing
    Set xlFile = Nothing
    MsgBox "Processing Complete"
    Exit Sub
    Err_Handle:
    MsgBox Err.Number & vbCrLf & Err.Description
    End Sub
  • BSOB
    New Member
    • Jul 2006
    • 77

    #2
    ok, without taking the time to think (which i find is usualy best in programming) i would say make arrays. take your varaibles and dim them with a (10) on the end like:
    dim x(10) as integer
    this makes 11 x's to work with (or 11 files). if the code works once, it will work again.
    so... for next loop time!

    Dim i As Double(4)
    Dim SRSWordStr(4) As String
    Dim newStart(4) As Double
    Dim tmpStrStart(4) As Double
    Dim tmpStrEnd(4) As Double
    Dim StopFinding(4) As Boolean
    Dim OneSRSTagInfo(4 ) As String
    const filesopen = 5
    for j = 0 to filesopen-1
    '<insert the rest of your code here and at the end of each varable put '(j)'.
    next j

    'note that i havent understoon your code snipit as there are variables with different scopes like rw that i dont understand there purpose.
    'there is the posibility my help has been completely useless. yah...

    Comment

    • Big K Hutch
      New Member
      • Jul 2006
      • 11

      #3
      Does this code not open word but also Excel?

      Comment

      • siddhi
        New Member
        • Jul 2006
        • 3

        #4
        what it basically does is ...opens word files and get information and put it in excel. I have one file to excel but not multiple files working. I am not sure how would i deal with arrays when I have to set the SRSWordApp As Word.Applicatio n.....like..

        Dim cellno As String
        Dim rw As Double
        Dim cChar As String

        Dim SRDDWordStr As String
        Dim SRSWordApp As Word.Applicatio n
        Dim SRDDWordApp As Word.Applicatio n

        Dim xlFile As Excel.Applicati on
        Dim ArrayNum As Double
        Dim TermArray() As String

        after that..i have process method as above. Thanks A Bunch for the replys guys..

        Comment

        Working...