Results 1 to 9 of 9

Thread: Scanning Word Document

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Arrow 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.
    Microsoft Techie

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Scanning Word Document

    Search the document, Read the Word document character by character, so that I can remove consecutive spaces and line breaks.
    Microsoft Techie

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    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
    Microsoft Techie

  6. #6

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Scanning Word Document

    ????
    Microsoft Techie

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  8. #8

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Scanning Word Document

    thx...i will go thru it
    Microsoft Techie

  9. #9

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: Scanning Word Document

    koolsid...after studying the link that u provided...I do the following:
    VB Code:
    1. With WordApp
    2.             .Selection.HomeKey(Word.WdUnits.wdStory)
    3.             PrevChar = .Selection.Text
    4.             .Selection.MoveRight(Word.WdUnits.wdCharacter, 1)
    5.             Do While True
    6.                 If .Selection.Text = " " And .Selection.Start = 0 Then
    7.                     .Selection.Delete()
    8.                     GoTo ResumeLoop
    9.                 End If
    10.                 If PrevChar = " " And .Selection.Text = " " Then
    11.                     .Selection.Delete()
    12.                 Else
    13.                     PrevChar = .Selection.Text
    14.                     .Selection.MoveRight(Word.WdUnits.wdCharacter, 1)
    15.                 End If
    16. ResumeLoop:
    17.             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
    Microsoft Techie

Posting Permissions

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



Click Here to Expand Forum to Full Width