|
-
Jan 16th, 2007, 06:48 AM
#1
Thread Starter
Fanatic Member
Scanning Word Document
Hi all,
How can I scan the word document right frm the beginning till the end.
Basically I want to remove extra (consecutive) spaces & line breaks within the word document.
Pls guide.
-
Jan 16th, 2007, 11:59 AM
#2
Re: Scanning Word Document
What do you mean "scan"? Like actually scanning a document with a scanner or search the document?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 16th, 2007, 12:15 PM
#3
Thread Starter
Fanatic Member
Re: Scanning Word Document
Search the document, Read the Word document character by character, so that I can remove consecutive spaces and line breaks.
-
Jan 16th, 2007, 12:16 PM
#4
Re: Scanning Word Document
Using the Content property of the document object will give you access to every character. alternativitly you can use the .Find and .Replace methods too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 17th, 2007, 06:04 AM
#5
Thread Starter
Fanatic Member
Re: Scanning Word Document
The prob with the find and replace is that it has to be repeated again and again till the consecutive spaces are not eleminated...also i cant remove consecutive lines.
As far as Content property is concerend, can you give me some code snippets or links to any tutorial pages??
Thnx in advance
-
Jan 17th, 2007, 09:08 AM
#6
Thread Starter
Fanatic Member
Re: Scanning Word Document
-
Jan 17th, 2007, 09:46 AM
#7
Re: Scanning Word Document
Does this help?
http://word.mvps.org/FAQs/MacrosVBA/index.htm
look under [Strings, Dates and Find and Replace]
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 17th, 2007, 10:34 AM
#8
Thread Starter
Fanatic Member
Re: Scanning Word Document
-
Jan 18th, 2007, 09:15 AM
#9
Thread Starter
Fanatic Member
Re: Scanning Word Document
koolsid...after studying the link that u provided...I do the following:
VB Code:
With WordApp
.Selection.HomeKey(Word.WdUnits.wdStory)
PrevChar = .Selection.Text
.Selection.MoveRight(Word.WdUnits.wdCharacter, 1)
Do While True
If .Selection.Text = " " And .Selection.Start = 0 Then
.Selection.Delete()
GoTo ResumeLoop
End If
If PrevChar = " " And .Selection.Text = " " Then
.Selection.Delete()
Else
PrevChar = .Selection.Text
.Selection.MoveRight(Word.WdUnits.wdCharacter, 1)
End If
ResumeLoop:
Loop
It solves my purpose...but its too slow. Is there any better method to do the same??? Basically I want to remove unwated spaces and carriage returns in the document.
For example the original text is:
| This is a text with |
| unwanted spaces and |
| line breaks |
The same as to be edited as follows:
|This is a text with unwated |
|spaces and line breaks|
I hope its clear
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|