Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2014, 07:34 AM
skyslayer skyslayer is offline We have many word docs we need to copy text from Windows 7 64bit We have many word docs we need to copy text from Office 2013
Novice
We have many word docs we need to copy text from
 
Join Date: Aug 2014
Posts: 11
skyslayer is on a distinguished road
Default

Graham


You are the man! thank you again

I still have one problem
all is well until I get to the end at
Code:
oNewDoc.SaveAs strNewName, addtorecentfiles:=False
if I comment out On Error that line of code spits out this error code
Run-time error 6015:
A table in the document has become corrupted.
There are tables in the doc and they are not needed in the new doc they are before and after search strings

the result is the new document or documents will not close, if I keep going in the code all looks good in the new doc except for a empty table that could go away it is not needed.

I am looking for solutions on-line as well

Again thanks Jim
Reply With Quote
  #2  
Old 08-29-2014, 12:10 PM
skyslayer skyslayer is offline We have many word docs we need to copy text from Windows 7 64bit We have many word docs we need to copy text from Office 2013
Novice
We have many word docs we need to copy text from
 
Join Date: Aug 2014
Posts: 11
skyslayer is on a distinguished road
Default

Update
I have discovered that the original ExtractText function somehow inserts the last table before the start
search string into the new document because I am a beginer to all this the only way for me to remove the added table or tables are to remove them
using the Sub Removetables.

My problem now is in order for my new Sub to run on the new document I need to set oNewDoc = Documents.Add(Template:=oDoc.FullName, Visible:=True)
but when it is set to true the Batch Process Documents Add-in does not work so I must do them one at a time, If I set it to False the Batch Process Documents Add-in
works with error corrupted tables as in last post but my Sub runs on the active document (the original).
I am assuming this is somthing simple but at this stage of my grasp of VBA I am at a loss.

Thank You
Jim

Code:
 
 Sub TestENV2()
ExtractTextENV2 ActiveDocument
End Sub
 Function ExtractTextENV2(oDoc As Document) As Boolean
Dim oRng As Range
Dim oNewDoc As Document
Dim strNewName As String
Const strStart As String = "The information received does not support the service requested:"
Const strEnd As String = "The above actions are supported by the following:"
    On Error GoTo Err_Handler
    Set oRng = oDoc.Range
    With oRng
        .Start = .Start + InStr(oRng, strStart) - 1
        .End = .Start + InStr(oRng, strEnd) + 1
        .MoveEndUntil Chr(58)
        .End = .End + 1
        If Len(.Text) > 0 Then
            Set oNewDoc = Documents.Add(Template:=oDoc.FullName, Visible:=True) '<---If set to True Sub Removetables works fine
            'but Batch Process Documents Add-in does not work if set to False Batch Process Documents works but Sub Removetables
            'does not work
            oNewDoc.Range.FormattedText = oRng.FormattedText
            strNewName = oDoc.FullName
            strNewName = Left(strNewName, InStrRev(strNewName, Chr(46)) - 1)
            strNewName = strNewName & "EN"
            strNewName = strNewName & Right(oDoc.Name, Len(oDoc.Name) - InStrRev(oDoc.Name, Chr(46)) + 1)
            Call Removetables '<---new call to Sub to remove all tables in new document (by Jim)
            oNewDoc.SaveAs strNewName, addtorecentfiles:=False
            oNewDoc.Close 0
        End If
    End With
    ExtractTextENV2 = True
 lbl_Exit:
    Exit Function
Err_Handler:
    ExtractTextENV2 = False
End Function
 
 'This Sub used to remove all tables in new document
Sub Removetables()
Dim oTable As Table
Dim oNewDoc As Document
Set oNewDoc = ActiveDocument
On Error Resume Next
For Each oTable In ActiveDocument.Tables
oTable.Delete
Next oTable
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Text Twice to Paste into word Albundy Word 2 09-02-2016 12:59 PM
Text Shifting When Saving Word 2007 Docs DerekS Word 1 09-21-2013 02:42 AM
Can't copy/cut and paste text in Word 2002 mmiller751 Word 0 04-17-2012 02:55 PM
We have many word docs we need to copy text from copy from word into a formatting text box mikewooten Word 1 06-15-2010 02:04 AM
We have many word docs we need to copy text from Is it possible to create 'balloon' text in docs bubbleboi Word 3 11-13-2009 01:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft