Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2014, 12: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 first character NOT Alpha numeric or Tilde (~) delete.

Hi,



I have the GRE words list that I have copied from a PDF file to Word. First character of each line in this Word file is NOT an alphanumeric one or Tilde (~). If they are, I want to move to next line, otherwise delete that character and the space joining it. I need to do this to all lines.

Here is my Code and this works fine only for first few lines and goes for a toss:
--------------------------------------
Code:
Sub FormatData()
     'Declare variables
    Dim numOfLines As Integer
    Dim ascVal As Integer
    Dim doc As Document
    Set doc = ActiveDocument
     '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
     'ascVal = (Asc(doc.Sentences(58).Characters(1).Text))
     'MsgBox (ascVal)
    For x = 1 To numOfLines
         'MsgBox (x)
        ascVal = (Asc(doc.Sentences(x).Characters(1).Text))
         'MsgBox (ascVal)
        Selection.HomeKey Unit:=wdLine
        If Not (((ascVal >= 65 And ascVal <= 90) Or (ascVal >= 97 And ascVal <= 122) Or (ascVal >= 48 And ascVal <= 57) Or (ascVal = 126))) Then
             'MsgBox  (doc.Sentences(x).Characters(1).Text)
            Selection.Delete Unit:=wdCharacter, Count:=2
            Selection.MoveDown Unit:=wdLine, Count:=1
            Selection.HomeKey Unit:=wdLine
             'MsgBox (x)
        Else
            Selection.MoveDown Unit:=wdLine, Count:=1
            Selection.HomeKey Unit:=wdLine
        End If
         'Selection.HomeKey Unit:=wdLine
    Next
End Sub
------------------------------------

Thanks.....Karthik....

Last edited by macropod; 03-15-2014 at 05:01 AM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 03-15-2014, 03:03 AM
macropod's Avatar
macropod macropod is offline first character NOT Alpha numeric or Tilde (~) delete. Windows 7 32bit first character NOT Alpha numeric or Tilde (~) delete. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13[!A-Za-z0-9~] "
    .Replacement.Text = "^p"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
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
  #4  
Old 03-15-2014, 05:15 AM
macropod's Avatar
macropod macropod is offline first character NOT Alpha numeric or Tilde (~) delete. Windows 7 32bit first character NOT Alpha numeric or Tilde (~) delete. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  .InsertBefore vbCr
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13[A-Za-z0-9~]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    .Text = "^13[!A-Za-z0-9~] "
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
  End With
  .Characters.First = vbNullString
End With
Application.ScreenUpdating = True
End Sub
If the above doesn't do what you want, please attach a document to a post with some representative before and after data (delete anything sensitive). You do this via the paperclip symbol on the 'Go Advanced' tab - don't simply post more code that doesn't work.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-17-2014, 12:33 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. The code works fine for my 2nd point.

But I am not able to achieve my 1st point.

Previously, I searched for first line to be any character other than alphanumerics or tilde.
Now, after your recent code that does its magic , I am checking if the first character of each line is bold, then move to next line and if not add that line to the previous line, so that the words synonyms are in 1 single line and not multiple ones, as in the attachment.

Please help on this and you can see the code that I use in Sub joinLines().

Cheers....
Attached Files
File Type: docx Text Manipulation.docx (22.2 KB, 10 views)
Reply With Quote
  #6  
Old 03-17-2014, 12:45 AM
macropod's Avatar
macropod macropod is offline first character NOT Alpha numeric or Tilde (~) delete. Windows 7 32bit first character NOT Alpha numeric or Tilde (~) delete. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

In my last post, I asked that you:
Quote:
attach a document to a post with some representative before and after data
Your attached document gives no indication of what needs changing; for starters, there are no ~ characters anywhere in the document!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
delete first character

Thread Tools
Display Modes


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 08:28 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