View Single Post
 
Old 05-14-2014, 08:46 PM
egyp7 egyp7 is offline Windows 7 64bit Office 2007
Novice
 
Join Date: May 2014
Posts: 2
egyp7 is on a distinguished road
Default VBA Code for clean all data from ms word document

Hello all members. I need some help/or ready solution for my problem.
There is ms word document with somethin' data. I need clean all data from document and paste my text or data in that doc with vba macros.
I alredy have some solution but workn't with big document(50-60 pages)
and not delete any data exclude text :
Code:
Sub CleanData()
Dim curCharIndex As Integer
Dim charCount As Integer
curCharIndex = 1
charCount = ActiveDocument.Characters.Count

While curCharIndex <= charCount
    ActiveDocument.Characters(curCharIndex).Select
    If Selection.Type = wdSelectionNormal Then
        Selection.Delete
        charCount = charCount - 1
    Else
        'Skip it
        curCharIndex = curCharIndex + 1
    End If
Wend
End Sub
That's first problem in that solution, second problem is hard load for CPU/RAM.
Maybe there is any way emulate marking all text(Ctrl+A) and delete that text(by DEL button) from word document not so dirty like my solution.
I'm sorry for my poor english. Thanx, with best regards, egyp7
Reply With Quote