Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2014, 04:54 AM
ksridh ksridh is offline first character NOT Alpha numeric or Tilde (~) delete. Windows 7 32bit first character NOT Alpha numeric or Tilde (~) delete. Office 2010 32bit
Novice
first character NOT Alpha numeric or Tilde (~) delete.
 
Join Date: Mar 2014
Posts: 3
ksridh is on a distinguished road
Default

Thanks. Paul.

These are the ones I want to achieve:
1. I want to first join all lines that start with an alphabet or Tilde (~) to their previous lines.
2. Remove the first character and its joining spaces in each line if the character is not alphanumeric or Tilde (~) - You have given the code for this but it leaves the first line and does the changes for all remaining lines.

The code I am trying for 1st point which I got from the net is:
--------------------------------------------------------------------


Code:
Sub LoopingText() 
     'Will move to the end of each line in the document and move the text to match
     'Declare variables
    Dim outputStr As String 
    Dim currLine As String 
    Dim endChar As String 
    Dim numOfLines As Integer 
    Dim ascVal As Integer 
     'Count the number of non blank lines in current document
    numOfLines = ActiveDocument.BuiltInDocumentProperties("NUMBER OF LINES") 
     'Move to start of document
    Selection.HomeKey Unit:=wdStory 
     'Start the loop - looping once for each line
    For x1 = 1 To numOfLines 
         'MsgBox (x1)
         'ascVal = (Asc(doc.Sentences(x1).Characters(1).Text))
        ascVal = (Asc(ActiveDocument.Sentences(x1).Characters(1).Te xt)) 
         'Move to start of line
        Selection.HomeKey Unit:=wdLine 
         'Select entire line and copy into variable currLine
        Selection.EndKey Unit:=wdLine, Extend:=wdExtend 
        currLine = Selection.Range.Text 
         'Remove final character (line break) from currLine
        currLine = Left(currLine, (Len(currLine) - 1)) 
         'Check to see if character currently on end of outputStr is " " (space)
        endChar = Right(outputStr, 1) 
        If x1 = 1 Then 
             'Add the current line to the variable outputStr
             'Since this is the first run through, don't add a space
            outputStr = outputStr & currLine 
            Selection.MoveDown Unit:=wdLine, Count:=1 
            Selection.HomeKey Unit:=wdLine 
        Else 
            If Not (endChar = " ") And (((ascVal >= 65 And ascVal <= 90) Or (ascVal >= 97 And ascVal <= 122) Or (ascVal >= 48 And ascVal <= 57) Or (ascVal = 126))) Then 
                 
                 'If preceding line does not have a space at the end
                 'Add current line to the variable outputStr
                outputStr = outputStr & " " & currLine 
                Selection.EndKey Unit:=wdLine 
                Selection.TypeParagraph 
                Selection.MoveDown Unit:=wdLine, Count:=1 
                Selection.HomeKey Unit:=wdLine 
            Else 
                Selection.MoveDown Unit:=wdLine, Count:=1 
                Selection.HomeKey Unit:=wdLine 
            End If 
        End If 
         
         'Move down one line
        Selection.MoveDown Unit:=wdLine, Count:=1 
         
         'Move to the next part of the loop
    Next x1 
     'Finally 'paste' outputStr onto the document
    ActiveDocument.Range = outputStr 
    ActiveDocument.Save 
End Sub
--------------------------------------------------------------------
This code just joins all lines together irrespective of my conditions.

Please help....Thanks....Karthik....

Last edited by macropod; 03-15-2014 at 05:09 AM. Reason: Added code tags & formatting
Reply With Quote
Reply

Tags
delete first character



Similar Threads
Thread Thread Starter Forum Replies Last Post
first character NOT Alpha numeric or Tilde (~) delete. How to do an alpha numeric Sort By? Opul3nce Excel 1 10-15-2012 11:11 PM
first character NOT Alpha numeric or Tilde (~) delete. Unique 3 char Alpha Numberic column mauricioaglr Excel 7 03-09-2012 06:45 PM
first character NOT Alpha numeric or Tilde (~) delete. Word 2007 TOC Section Number w/Alpha Prefix? Gwen Butler Office 2 09-29-2011 06:10 AM
first character NOT Alpha numeric or Tilde (~) delete. Place pages in alpha order. Wskip49 Word 5 08-28-2011 07:54 PM
first character NOT Alpha numeric or Tilde (~) delete. [How To] Generate Alpha Numeric Values in Excel 2010 stnicholas81 Excel 1 07-25-2011 01:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:15 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