Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2021, 09:53 PM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Post Putting parentheses around sequence number of caption label

Hi,


I created a custom label for captioning figures and tables, see below
02.png
I want to put parentheses () around the sequential number to appear as below (Manually created through editing field code):
03.png

I tried to find and replace through showing all field codes (by pressing Alt-F9), and then searching for
{Seq Appendix \* Arabic}
and replace it to
({Seq Appendix \* Arabic})
My problem is each time, it tells me "No result found"
but when removing braces {}, a result appears
So how to fix this problem or any other method to put parentheses around sequence number of caption label.
Reply With Quote
  #2  
Old 10-21-2021, 03:55 AM
wiganken wiganken is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Expert
 
Join Date: Jul 2018
Posts: 279
wiganken will become famous soon enough
Default

Are the parentheses necessary or just a preference? Just wondering if you are making problems for yourself, that's all. Maybe accept the label without parentheses? Just a thought.

Hope you get an answer though.
Reply With Quote
  #3  
Old 10-21-2021, 04:05 AM
gmayor's Avatar
gmayor gmayor is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
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

A simple macro should do the trick
Code:
Sub Macro1()
Dim oFld As Field
    For Each oFld In ActiveDocument.Fields
        If oFld.Type = wdFieldSequence Then
            If InStr(1, oFld.Code, "Appendix") > 0 Then
                oFld.Result.InsertAfter ")"
                oFld.Result.InsertBefore "("
            End If
        End If
    Next oFld
    Set oFld = Nothing
End Sub
Installing Macros
__________________
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
  #4  
Old 10-21-2021, 06:13 AM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by wiganken View Post
Are the parentheses necessary or just a preference? Just wondering if you are making problems for yourself, that's all. Maybe accept the label without parentheses? Just a thought.
I totally agree with you, and the parentheses are not necessary!!!
But what I can do with faculty preferences, they inform me to use this pattern.
Reply With Quote
  #5  
Old 10-21-2021, 06:31 AM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
A simple macro should do the trick
Thank you so much my bro
It works fine, but it has a problem
It does its job if the text is present in the main body of the document, but if the text is present in the text box (I always make a group for the figure and its caption), it ignores it.
See below,
Appendix 1 caption is present in the text box, while Appendix 2 is present in the main body of the document.
04.png
Hence my bro fixes it if you can.
Thank you again
Reply With Quote
  #6  
Old 10-21-2021, 08:28 AM
Charles Kenyon Charles Kenyon is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Using a macro to replace text where ever it appears in a document including Headers, Footers, Textboxes, etc.
Reply With Quote
  #7  
Old 10-21-2021, 01:19 PM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Thank you MR. Charles
Again the above macros work to find and replace normal text anywhere, but do not look for the text of field codes ex: {Seq Appendix \* Arabic}.
Here the sample file you can try to explore what I mean.
Attached Files
File Type: docx Sample.docx (190.1 KB, 10 views)

Last edited by laith93; 10-21-2021 at 09:25 PM.
Reply With Quote
  #8  
Old 10-21-2021, 05:39 PM
Charles Kenyon Charles Kenyon is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,081
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by laith93 View Post
Thank you MR. Charles
Again the above macros work to find and replace normal text anywhere, but do not look for the text of field codes ex: {Seq Appendix \* Arabic}.
Here the sample file you can try to explore what I mean.
That page shows how to loop through stories in a document to get to all parts.


Code:
Sub AppendixParens()
'   Charles Kenyon using code from Graham Mayor
'   October 21, 2021
'   https://www.msofficeforums.com/word/47835-putting-parentheses-around-sequence-number-caption-label.html
    Dim oStory As range, oFld as Field
    On Error Resume Next
    For Each oStory In ActiveDocument.StoryRanges
        Do
            For Each oFld In oStory.Fields
                If oFld.Type = wdFieldSequence Then
                    If InStr(1, oFld.Code, "Appendix") > 0 Then
                        oFld.Result.InsertAfter ")"
                        oFld.Result.InsertBefore "("
                    End If
                End If
            Next oFld
        Loop Until oStory Is Nothing
     Next
    Set oFld = Nothing
    Set oStory = Nothing
    On Error GoTo -1
 End Sub
Reply With Quote
  #9  
Old 10-21-2021, 07:42 PM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Sub AppendixParens()
Thank you again, Mr. Charles
I applied your code on my sample file, as it contains only two caption
It takes about 15 mins without any changes until an error message appears "Not responding"
05.png
My laptop RAM is almost full, and fan speed was increased, although I have a laptop with (CPU Intel Core i7, RAM 8GB, GPU 2GB).
Any recommendation, please?
Reply With Quote
  #10  
Old 10-21-2021, 08:53 PM
gmayor's Avatar
gmayor gmayor is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
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

Documents comprise several separate story ranges which make up the whole - much like a stack of transparencies.

The code I posted earlier acts only on the main story range i.e. the body of the document. Where other ranges need to be processed you meed to address those ranges separately.
Code:
Sub Macro1()
Dim oFld As Field
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        For Each oFld In oStory.Fields
            If oFld.Type = wdFieldSequence Then
                If InStr(1, oFld.Code, "Appendix") > 0 Then
                    oFld.Result.InsertAfter ")"
                    oFld.Result.InsertBefore "("
                End If
            End If
        Next oFld
        oStory.Fields.Update
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oFld In oStory.Fields
                    If oFld.Type = wdFieldSequence Then
                        If InStr(1, oFld.Code, "Appendix") > 0 Then
                            oFld.Result.InsertAfter ")"
                            oFld.Result.InsertBefore "("
                        End If
                    End If
                Next oFldoStory.Fields.Update
            Wend
        End If
        DoEvents
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set oFld = Nothing
    Exit Sub
End Sub
As your Word crashed - reboot the laptop and see https://www.gmayor.com/what_to_do_when_word_crashes.htm regarding orphaned files.
__________________
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
  #11  
Old 10-21-2021, 09:00 PM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Documents comprise several separate story ranges which make up the whole - much like a stack of transparencies.

The code I posted earlier acts only on the main story range i.e. the body of the document. Where other ranges need to be processed you meed to address those ranges separately.
Thank you for these info
I appreciate your time and effort
Mr. Graham, this error message appears

06.png
Reply With Quote
  #12  
Old 10-21-2021, 09:06 PM
gmayor's Avatar
gmayor gmayor is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
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

Sorry I had just spotted that and was about to correct it
There's a missing line break in that line
Change
Code:
Next oFldoStory.Fields.Update
to
Code:
Next oFld
oStory.Fields.Update
__________________
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
  #13  
Old 10-21-2021, 09:16 PM
laith93 laith93 is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Competent Performer
Putting parentheses around sequence number of caption label
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Sorry I had just spotted that and was about to correct it

Don't worry my bro
I'm sorry for annoying and be patient
Mr. Graham, the error message was solved, but there are no changes in the document???
Reply With Quote
  #14  
Old 10-21-2021, 11:52 PM
wiganken wiganken is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Expert
 
Join Date: Jul 2018
Posts: 279
wiganken will become famous soon enough
Default

I hope Graham and Charles fix it for you but you may need a fall back plan: - If real-world experts like Graham and Charles don't find an answer then consider telling the faculty that their parentheses requirement isn't practical and ask them to remove the requirement.

Just a thought. Best wishes for a good result though.
Reply With Quote
  #15  
Old 10-22-2021, 12:04 AM
gmayor's Avatar
gmayor gmayor is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
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

Can you post a sample document, or send it to my web site.
__________________
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
find & replace, find replace;wildcards, word 19

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for number sequence 14spar15 Excel Programming 4 03-18-2018 07:00 PM
Putting parentheses around sequence number of caption label Assigning a string variable to a userform label caption Larry_1 Excel Programming 3 12-18-2017 06:59 AM
Putting parentheses around sequence number of caption label how to have two formats in the Caption style: Label – number - text? Jamal NUMAN Word 39 03-14-2017 06:32 PM
Putting parentheses around sequence number of caption label Custom caption list label lost in a new Word session New Daddy Word 1 09-22-2013 09:21 AM
Custom caption label annoyance zac Word 1 08-29-2010 09:56 AM

Other Forums: Access Forums

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