Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-14-2014, 08:46 PM
egyp7 egyp7 is offline VBA Code for clean all data from ms word document Windows 7 64bit VBA Code for clean all data from ms word document Office 2007
Novice
VBA Code for clean all data from ms word document
 
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
  #2  
Old 05-15-2014, 04:49 PM
macropod's Avatar
macropod macropod is offline VBA Code for clean all data from ms word document Windows 7 32bit VBA Code for clean all data from ms word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why are you bothering with this? Surely you could just create a new, empty document?! Still, if that's what you want, try:
Code:
Sub CleanData()
ActiveDocument.Content.Delete
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-16-2014, 04:41 AM
egyp7 egyp7 is offline VBA Code for clean all data from ms word document Windows 7 64bit VBA Code for clean all data from ms word document Office 2007
Novice
VBA Code for clean all data from ms word document
 
Join Date: May 2014
Posts: 2
egyp7 is on a distinguished road
Default

thank for answer macropod, i already find way clean document data and paste my content. my solution look like :
Code:
Sub doc_clean_paste()

Word.ActiveDocument.Range.Select
    Selection.WholeStory
    Selection.Delete Unit:=wdCharacter, Count:=1
    
   Dim doc As Word.Document
   Set doc = ThisDocument 
   
   doc.Range.InsertParagraphAfter
   doc.Range.InsertAfter "Text Added at " & Time
End Sub
Reply With Quote
  #4  
Old 05-16-2014, 12:22 PM
fumei fumei is offline VBA Code for clean all data from ms word document Windows 7 64bit VBA Code for clean all data from ms word document Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

This does the exact same thing.
Code:
Sub SameThing()
With ActiveDocument
   .Content.Delete
   .Range.InsertAfter vbCrLf & "Text Added at " & Time
End With
End Sub
You do not need to select anything. You certainly do not need to select the same thing twice.


These two instruction do the same thing.
Word.ActiveDocument.Range.Select
Selection.WholeStory

You take seven lines to do what can be done in two.
Reply With Quote
  #5  
Old 05-16-2014, 03:59 PM
macropod's Avatar
macropod macropod is offline VBA Code for clean all data from ms word document Windows 7 32bit VBA Code for clean all data from ms word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Or even one:
Code:
Sub SameThing()
ActiveDocument.Range.Text = vbCrLf & "Text Added at " & Time
End Sub
Egyp7: Perhaps you should have another go at explaining what you're trying to achieve, instead of trying to tell us how you want to do it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code for clean all data from ms word document VBA Code to take data from a table in word document and place it in a summary table VBLearner Word VBA 1 03-09-2014 08:42 PM
importing Access data to a Word document WayneCusack Word VBA 2 12-24-2012 12:26 AM
VBA Code for clean all data from ms word document Help Plz! Link Excel data to Word document cory_0101 Office 1 09-27-2012 07:15 PM
VBA Code for clean all data from ms word document How do you view the source code in a Word 10 web document? provlima Word 2 05-25-2012 01:12 PM
VBA Code for clean all data from ms word document Error Code 5453 Word has finished searching the document Charles Kenyon Word VBA 2 05-17-2012 11:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:32 AM.


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