Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2020, 04:47 AM
pradeepraomusale pradeepraomusale is offline Get the symbol contain names in word using macros Windows 10 Get the symbol contain names in word using macros Office 2010
Novice
Get the symbol contain names in word using macros
 
Join Date: Jun 2020
Posts: 1
pradeepraomusale is on a distinguished road
Default Get the symbol contain names in word using macros

I am new for word macros. Can you anyone please suggest to me how to write a code in macros for the below solution.

I need to get the text contains special symbols("-") in between text in the word document macros.



This is the table of content we are using in word, Each heading having serial number also

Code:
1 test1
2 test2
3 -  test3 -  
4 test4
5 -  test5 -  
6 test6
7 -  test7 -  
8 test8
9 -  test9 -  
10 test10
11 test11
12 -  test12 -  
13 test13
14 -  test14 -
the result should be need like

Code:
 -  test3 -  
 -  test5 -  
 -  test7 -  
 -  test9 -  
 -  test12 -  
 -  test14 -
This is the sample code I wrote but it not working it getting only single text "-" in the collection
Code:
Public Function GetVariablesFirstLevel() As Collection
On Error GoTo ErrorHandler
    Dim objVar As variable
    Dim colAux As Collection
    Dim strAux As String
    Dim objStoryRange As Range
    Dim forceExitLoop As Boolean
            
    Set colAux = New Collection
    For Each objStoryRange In ActiveDocument.StoryRanges
        objStoryRange.Select
        Selection.Collapse wdCollapseStart
        With Selection
            With .Find
                .ClearFormatting
                .Text = "-"
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = False
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            forceExitLoop = False
            Do While (.Find.Execute And Not forceExitLoop)
                strAux = Trim$(Replace$(Right(.Text, 1), vbCr, vbNullString))
                If (strAux <> vbNullString) Then
                    If (Not IsReplacementOfAVariable(strAux)) Then
                        colAux.Add strAux, UCase$(strAux)
                    End If
                Else
                    forceExitLoop = True
                End If
            Loop
        End With
    Next
    
    Set GetVariablesFirstLevel = colAux
    Set colAux = Nothing
    Set objStoryRange = Nothing
Exit Function
End Function
Reply With Quote
  #2  
Old 06-25-2020, 05:10 AM
gmayor's Avatar
gmayor gmayor is offline Get the symbol contain names in word using macros Windows 10 Get the symbol contain names in word using macros Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

How about


Code:
Public Function GetVariablesFirstLevel() As Collection
Dim objVar As Variable
Dim colAux As Collection
Dim strAux As String
Dim objStoryRange As Range
Dim i As Integer

    Set colAux = New Collection
    For Each objStoryRange In ActiveDocument.StoryRanges
        With objStoryRange.Find
            .ClearFormatting
            Do While .Execute(findText:="- * -", MatchWildcards:=True)
                'strAux = Trim(Replace(objStoryRange.Text, "-", ""))
                strAux = objStoryRange.Text
                colAux.Add strAux, UCase$(strAux)
                objStoryRange.Collapse 0
            Loop
        End With
    Next objStoryRange
    'For i = 1 To colAux.Count
    'Debug.Print colAux(i)
    '    Next i
    GetVariablesFirstLevel = colAux
    Set colAux = Nothing
    Set objStoryRange = Nothing
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
vba, word macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/replace - symbol for all numbers or symbol letters (Word 97) Genericname1111 Word 10 11-10-2019 10:37 PM
Get the symbol contain names in word using macros Foot symbol/inches symbol Mr. P Word 1 09-05-2016 11:55 AM
Get the symbol contain names in word using macros Make my own image and save as symbol in the symbol chart DeniseN Office 1 03-20-2015 01:13 AM
Get the symbol contain names in word using macros how to find and replace a symbol with another symbol wondermuse Word 5 10-09-2014 06:30 AM
How to enter names in Resource Pool/names pstein Project 1 03-26-2012 07:37 AM

Other Forums: Access Forums

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