Results 1 to 3 of 3

Thread: can some one look at this please

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Lightbulb can some one look at this please

    I attached a small word file I am trying to find a way to modify this code so that is picks up only the words that come aftert application and stops picking up words when it gets to the of the cell in that particular table I have written two codes that may be able to do that but I cant seem to get them to do this particular task. here is the first code.

    VB Code:
    1. Sub Date_in()
    2.  
    3.     Dim r As Range
    4.     Dim rword As Range
    5.     Dim h As Long, l As Long
    6.     Dim xlApp As Excel.application
    7.     Dim xlWB As Excel.Workbook
    8.    
    9.    
    10.    
    11.    
    12.     'find the marker
    13.    
    14.     Set r = ActiveDocument.Range
    15.    
    16.    
    17.     With r.Find
    18.         .ClearFormatting
    19.         .Text = "Application:"
    20.         .MatchCase = True
    21.         .Forward = True
    22.        
    23.        
    24.         h = 2
    25.         '
    26.         Set xlApp = CreateObject("Excel.Application")
    27.                  xlApp.Visible = True
    28.                  Set xlWB = xlApp.Workbooks.Open("C:\Foldername\Day1.xls")
    29.         Do While .Execute
    30.             Set rword = ActiveDocument.Range
    31.             rword.start = r.End + 1
    32.             Debug.Print rword.Words(1)  
    33.                 h = h + 1
    34.                 With xlWB.Worksheets(1)
    35.                     .Cells(h, 4).Formula = rword.Words(1) & rword.Words(2) & rword.Words(3) & rword.Words(4) & rword.Words(5)
    36.                 End With
    37.                
    38.         Loop
    39.     End With
    40. End Sub



    Here is the second one

    VB Code:
    1. Sub application()
    2.     Dim r As Range
    3.     Dim rword As Range
    4.     Dim h As Long, l As Long
    5.     Dim xlApp As Excel.application
    6.     Dim xlWB As Excel.Workbook
    7.    
    8. 'With ActiveDocument
    9.     Dim seastring1 As String
    10.     Let seastring1 = ThisDocument.Content
    11.    
    12.     Const seastring2 As String = "  "
    13.     Const pook As String = "Application"
    14.     Set xlApp = CreateObject("Excel.Application")
    15.     xlApp.Visible = True
    16.     Set xlWB = xlApp.Workbooks.Open("C:\Foldername\Day1.xls")
    17.    
    18.  
    19.  
    20.  
    21. Dim j As Long
    22. Dim i As Long
    23. h = 2
    24. j = InStr(1, seastring1, seastring2)
    25. i = InStr(1, seastring1, pook)
    26. Do While i <> 0
    27.  
    28.  
    29.  
    30. h = h + 1
    31.                 With xlWB.Worksheets(1)
    32.                     .Cells(h, 9).Formula = Mid$(seastring1, i, j - i) ' & " | " & Len(Mid$(seastring1, i, j - i))
    33.                 End With
    34.  
    35. 'MsgBox Mid$(seastring1, i, j - i), Len(Mid$(seastring1, i, j - i))
    36. 'MsgBox pook & i
    37. 'MsgBox Mid$(seastring1, i, InStr(seastring1, seastring2) - i) ', Len(Mid$(seastring1, i, InStr(seastring1, seastring2) - i ))
    38. i = InStr(i + 1, seastring1, pook)
    39. j = InStr(j + 1, seastring1, seastring2)
    40. Loop
    41. 'End With
    42. End Sub


    and attached is the word doc. I working from
    Attached Files Attached Files
    • File Type: zip 5.zip (4.6 KB, 45 views)

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: can some one look at this please

    Hi,

    The following code might work for you if you receive the same setup (same type of document and in table format).

    VB Code:
    1. Sub Find_Text()
    2. Dim FinalText As String
    3. Dim I As Integer
    4. Dim xlApp As Excel.application
    5. Dim aFound As Boolean
    6.  
    7. Set xlApp = CreateObject("Excel.Application")
    8. xlApp.Visible = True
    9. xlApp.Workbooks.Open ("C:\Foldername\Day1.xls")
    10.  
    11. With Selection
    12.     'Move the cursor to top of the document
    13.     .HomeKey unit:=wdStory
    14. aFound = True
    15. I = 2
    16. Do
    17.     With .Find
    18.         .Execute findtext:="Application:", MatchCase:=True, Forward:=True, Wrap:=wdFindStop
    19.     If .Found Then
    20.         I = I + 1
    21.         Selection.MoveRight unit:=wdCell
    22.         FinalText = Trim(Selection.Text)
    23.         Debug.Print FinalText
    24.         xlApp.Workbooks("Day1.xls").Sheets(1).Cells(I, 4).Value = FinalText
    25.         aFound = True
    26.     Else
    27.         aFound = False
    28.     End If
    29.     End With
    30. Loop Until aFound = False
    31. End With
    32. End Sub

    Regards,

    CS.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: can some one look at this please

    Alright I attached a copy of one of the pages in the word doc what it is doin is picking up the first thing that shows up after application and stops after only picking up the first page for xample I ran it and it gave me "Software/Hardware Status:" and that is the first word that shows in the next table because there is no words after application in this particular page and then it stops those anyone know why it is doin that
    Attached Files Attached Files
    • File Type: zip 5.zip (4.6 KB, 40 views)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width