Results 1 to 5 of 5

Thread: Copy text from word to excel - "Out of disk space" error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Undoubtedly, creating multiple Word instances that you don't kill has choked your system(Hint: NewWordFile.Quit does not relate to Set NewDoc = CreateObject("word.application")). Your code has other issues, too.

    Here's a more flexible approach that allows for the possibility that doesn't require knowing in advance which paragraphs contain your strings or, especially for the second string, how long it might be:
    Sub Abrir()
    Dim StrFldr As String, StrFlNm As Strin, WdObj As Object, WdDoc As Object, xlSht As Worksheet, r As Long
    StrFldr = "C:\Users\njesus\Documents\Os meus documentos\": r = 1
    Set WdObj = CreateObject("Word.Application"): WdObj.Visible = False
    Set xlSht = ActiveSheet: xlSht.Range("A2:B" & Rows.Count).ClearContents
    StrFlNm = Dir(StrFldr & "*.doc*")
    Do While StrFlNm <> ""
      r = r + 1
      Set WdDoc = WdObj.Documents.Open(StrFldr & StrFlNm)
      With WdDoc
        With .Range
          With .Find
            .MatchWildcards = True
            .Text = "N/O Ref[!\:]@:[!/]@/[! ]@>"
            .Execute
          End With
          If .Find.Found Then xlSht.Range("A" & r).Value = Split(.Text, ":")(1)
        End With
        With .Range
          With .Find
            .MatchWildcards = True
            .Text = "ASSUNTO:[!^13]@^13"
            .Execute
          End With
          If .Find.Found Then xlSht.Range("B" & r).Value = Split(.Text, "ASSUNTO:")(1)
        End With
        .Close False
      End With
      StrFlNm = Dir()
    Loop
    Set WdDoc = Nothing: Set WdObj = Nothing: Set xlSht = Nothing
    End Sub
    Last edited by macropod; 07-07-2022 at 08:24 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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