Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2018, 06:25 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default Changing the names of text boxes

Hi



If my document has a few text boxes on it, I can see from the Selection Pane that they are usually called 'Text Box 1', 'Text Box 2' and so on.

When I merge to a new document, the numbers increase. So, for page 2 of a merged doc, the boxes that was Text Box 1 on the first page becomes Text Box 3 (since there are 2 text boxes on the page).

So far so good. My problem is that when I change the name of my text boxes to something else - eg Catflap1 and Catflap2, on the 2nd page they still have these names, they don't increment to Catflap3 and Catflap4, they keep the same name.

Now, I want to do some vba code that loops through the shapes collection, and this only looks at the first 2 text boxes if they don't increment. It still loops through the shapes collection, but it only looks at the first 2 shapes when I refer to them.

Can anyone tell me why renaming a text box stops word incrementing it's number when it merges? - and how to make it do it on renamed text boxes?

Sorry for the long-winded explanation!
Reply With Quote
  #2  
Old 05-03-2018, 06:49 AM
Charles Kenyon Charles Kenyon is online now Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,124
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

Could you post a sample document? The term "text box" has been applied to a number of very different Word features.

How to attach a screenshot or file in this forum.
Reply With Quote
  #3  
Old 05-04-2018, 02:25 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

Thanks for your reply.

I've created a mail merge document with 2 text boxes and renamed one of them. I then merge to create a new document.

I've attached this new doc. You can see the that the text box I renamed to 'MyBox' keeps that same name on every page, but the name of the one I left alone increments for each page.

I guess one way around this would be to refer to the text boxes by their number within the shapes collection using a counter as I loop through. Would be nice to be able to do it by name though.
Attached Files
File Type: docx Text Boxes.docx (21.6 KB, 10 views)
Reply With Quote
  #4  
Old 05-04-2018, 08:21 AM
Charles Kenyon Charles Kenyon is online now Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,124
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

I do not know how one renames a text box nor why. I see that you are talking about the graphic "text box" rather than a formfield.

00 deleteme 1.png

What problem is this giving you? I am guessing in a vba procedure. Each new iteration will be in a different section, so you could loop through sections as well. I do not understand the process by which Word adds numbers to identify the native text boxes.

It could be that if you added your text box to the text boxes building blocks and added it from that, it would simply show up as Text Box #. I do not know.

Hope this helps. Perhaps someone else will have some ideas.
Reply With Quote
  #5  
Old 05-08-2018, 02:42 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

Hi Charles

Thanks for your input - it is for a vba procedure:

I've got a loop through all the shapes in a document looking for text boxes where the text is overflowing, then shrinking it to fit.

It works well enough but is too slow on larger documents (1000+ pages), so I was looking at ways to speed it up - if I could restict the loop to only look at text boxes I thought would overflow instead of all of them, I thought it might speed it up a bit.

I thought if I could name the boxes it would be a good way of telling word only to look at the ones I wanted.

Ultimately I'm not sure this will help much anyway in terms of speed, and I may have to give this up and invest in some VDP software - like Printshop Mail.

If only Word had a good way to shrink text to fit for mail-merging, without having to resort to my clumsy vba efforts (or making it all narrow and unreadable)!


By the way, I renamed the boxes via the Selection Pane in the Page Layout menu - it lists the object names, so you can just double-click them and rename.
Reply With Quote
  #6  
Old 05-08-2018, 04:30 AM
Guessed's Avatar
Guessed Guessed is offline Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

What does your code look like for autofit shrinking the text? Perhaps we can provide a quicker way to manipulate all the text boxes. I doubt any method that resizes text boxes on 1000+ page documents is going to be lightning fast since each change will cause repagination but you could always stop screen updates.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 05-08-2018, 04:55 AM
Charles Kenyon Charles Kenyon is online now Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,124
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

The text boxes that I use do resize, especially expanding to accommodate more text. They will expand vertically. Could you use a smaller box and allow it to expand automatically when more text is inserted?
Reply With Quote
  #8  
Old 05-08-2018, 06:34 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

Hi both

Here's the code I use - I'd welcome any thoughts on how to make it go faster. It needs to be run after merging to a new document. I'm afraid it's a little messy:

Code:
Sub StopOverflow()

    Dim oShp As Shape
    Dim changecount As Integer
    Dim shapecount, shapemax, pcount, allpages, pagetemp As Long
    Dim Doc As Document
    Dim sbar As Boolean
    
    shapecount = 1
    shapemax = ActiveDocument.Shapes.Count
    
    Application.ScreenUpdating = False
    sbar = Application.DisplayStatusBar
    Application.DisplayStatusBar = True
    
    pagetemp = 0
    changecount = 0
    allpages = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
    
    For Each oShp In ActiveDocument.Shapes

        If oShp.Type = msoTextBox Then
        
           
            If ActiveDocument.Shapes(oShp.Name).TextFrame.Overflowing Then
                If ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange Like "*|v*" Then
                ' ignore - this is a barcode
                ElseIf ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange Like "*[a-z][a-z][a-z][a-z][a-z]-[a-z][a-z][a-z][a-z][a-z]-[a-z][a-z][a-z][a-z][a-z]*" Then
                ' ignore - this is a UN
                ElseIf ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange Like "*D# -*" Then
                ' ignore - this is a Delegate Code
                ElseIf ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange Like "*Full Pass*" Then
                ' ignore - this is a Full Pass code
                Else
                    Do While ActiveDocument.Shapes(oShp.Name).TextFrame.Overflowing
                        ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange.Font.Shrink
                    Loop
                    changecount = changecount + 1
                End If
           End If
            
        End If
        
        pcount = oShp.Anchor.Information(wdActiveEndPageNumber)
        
        If pagetemp <> pcount Then
            StatusBar = "                                                                                                                                            COMPLETE: " & pcount & " / " & allpages
            pagetemp = pcount
        End If
        
        DoEvents
        shapecount = shapecount + 1
        
    Next
    
    Application.StatusBar = False
    Application.DisplayStatusBar = sbar
    Application.ScreenUpdating = True

    MsgBox "Complete - " & changecount & " changes made."

End Sub
Where I've put in the remarks to ignore some text content relates to what I was thinking about when I mentioned renaming text boxes - it must take time to evaluate the text content in this way, I thought if I could just indicate the text boxes I was interested in, it would be a bit quicker.

I'm afraid I haven't quite got the hang of updating the screen with progress either - it flicks on and off annoyingly, but you can see it go through the pages. The reason there are so many spaces before the text in the StatusBar=" " line is to push the text into the middle of the screen so it doesn't get overwritten by Word.
Reply With Quote
  #9  
Old 05-08-2018, 06:45 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

Charles

Just following up your point, I need the text boxes to be fixed in size and have the text shrink to fit rather than the opposite way around.

This is for mailing badges which have a fixed area available to print, but variable length text. For example, if 2 names are:

Josephine Amanda Arkwright
Bob Smith

I need Josephine's whole name to appear, so font size needs to reduce. For Bob, the font can stay as it is (assuming I make it fairly big to start with).

In this way, both names roughly fit the badge without having a lot of white space left over and without truncating the names.

sorry I didn't explain this fully earlier!

Reply With Quote
  #10  
Old 05-08-2018, 07:18 AM
Guessed's Avatar
Guessed Guessed is offline Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would tag the text boxes I wanted to refit by putting something in the Alt Text property. This way you can use the same text every time
Code:
Sub ResizeTextInShapes()
  Dim aShp As Shape
  For Each aShp In ActiveDocument.Shapes
    With aShp.TextFrame
      If .HasText And aShp.AlternativeText <> "" Then
        Do While .Overflowing
          .TextRange.Font.Shrink
        Loop
      End If
    End With
  Next aShp
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 05-08-2018, 07:47 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

Looks interesting - I'll give it a go.

I've also being playing with Libre Office and that seems to have a 'fit text to frame' option, so that might be worth testing as well.

Cheers


UPDATE: Libre Office is a no-go. Writer will resize text to fit, but it doesn't work with merged text. I can't believe this is so difficult to achieve!

Last edited by catflap; 05-09-2018 at 06:20 AM.
Reply With Quote
  #12  
Old 05-09-2018, 07:47 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

I've just done a few speed trials. This is based on just 1 run of each category, so environmental factors could be having an influence.

This is running the 'shrink to fit' vba on a document of 100 pages.

Loop through only: 8 seconds
Shrink to fit on my original code: 80 seconds
Shrink to fit using the Alternative text idea to 'flag' text boxes from Guessed: 43 seconds

So there's been a definite improvement - thanks for the idea.

I now need to keep looking at this to see how much nearer I can get to the 8 seconds, which is literally looping through and doing nothing else that I'm going to use as a theoretical maximum speed!

Here's the latest code:
Code:
    Dim oShp As Shape
    Dim changecount As Integer
    Dim shapecount, shapemax, pcount, allpages, pagetemp As Long
    Dim Doc As Document
    Dim sbar As Boolean
    Dim timestart, timstop As Date
    
    timestart = Now()
    
    shapecount = 1
    shapemax = ActiveDocument.Shapes.Count
    
    Application.ScreenUpdating = False
    sbar = Application.DisplayStatusBar
    Application.DisplayStatusBar = True
    
    pagetemp = 0
    changecount = 0
    allpages = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
    
    For Each oShp In ActiveDocument.Shapes

        If oShp.Type = msoTextBox Then
                   
            If ActiveDocument.Shapes(oShp.Name).TextFrame.Overflowing Then
                If ActiveDocument.Shapes(oShp.Name).AlternativeText = "Shrink" Then
                               
                    Do While ActiveDocument.Shapes(oShp.Name).TextFrame.Overflowing
                        ActiveDocument.Shapes(oShp.Name).TextFrame.TextRange.Font.Shrink
                    Loop
                    changecount = changecount + 1
                    
                End If
           End If
            
        End If
        
        pcount = oShp.Anchor.Information(wdActiveEndPageNumber)
        
        If pagetemp <> pcount Then
            StatusBar = "                                                                                                                                            COMPLETE: " & pcount & " / " & allpages
            pagetemp = pcount
        End If
        
        DoEvents
        shapecount = shapecount + 1
        
    Next
    
    Application.StatusBar = False
    Application.DisplayStatusBar = sbar
    Application.ScreenUpdating = True
    
    timestop = Now()

    MsgBox "Complete - " & changecount & " changes made. Time taken: " & DateDiff("s", timestart, timestop) & " seconds"
Reply With Quote
  #13  
Old 05-09-2018, 05:48 PM
Guessed's Avatar
Guessed Guessed is offline Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

So a couple of things I would try to speed it up.

1. Use objects you already have in memory to reduce the number of memory steps required on a line. Once you have oShp in memory, there is no need to step back up multiple levels to use ActiveDocument.Shapes(oShp.Name) because you end up back at the very same shape. This adds considerable load for no value whatsoever.
Think of the code being asked repeatedly: first select a document, now in that document look through the shapes and find the one called something, now look in that shape at its textframe, is it overflowing? If so, go to another document (which happens to be the same as the one you were just thinking of), look through the shapes until you find one that happens to have the same name as the shape you already know about. Now look at that new shape's alttext and see if it says 'shrink'. If so go to another document (which happens to be the same as the one you were previously thinking of), look through the shapes until you find one that happens to have the same name as the shape you already know about. Look in that shapes TextFrame and see if it is overflowing. If so etc etc etc
Look at the way my sample code was structured - there was a reason ActiveDocument.Shapes appears once only.

2. Avoid repagination whereever possible. If you change your view to Draft view, this may allow Word to work without repeated repaginations. Also the fact that your loop asks for an active page number 'probably' forces a repagination (how else can Word know the answer?) - do you get a speed improvement if you stop asking for that?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #14  
Old 05-09-2018, 06:20 PM
Charles Kenyon Charles Kenyon is online now Changing the names of text boxes Windows 10 Changing the names of text boxes Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,124
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

Since this is a mailmerge, it is likely that your pages are also sections. Word does not need to repaginate to loop through sections.
Reply With Quote
  #15  
Old 05-10-2018, 12:57 AM
catflap's Avatar
catflap catflap is offline Changing the names of text boxes Windows 7 64bit Changing the names of text boxes Office 2013
Advanced Beginner
Changing the names of text boxes
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default

These are useful suggestions!

I'll make some changes and do some more trials.

EDIT: I've removed page references and now show progress on the statusbar by a count of the shapes instead. This has got us down to 20 seconds, so getting much better!

Last edited by catflap; 05-10-2018 at 03:24 AM.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the names of text boxes Formats in text boxes in Word 2016 changing unexpectedly PugwashAtNPEU Word 4 05-04-2017 05:53 AM
Changing Default Fonts for Text Boxes and Tables LadyBug679 PowerPoint 2 04-01-2016 06:42 AM
Changing the font colour in all text boxes marqives Word VBA 1 11-25-2014 06:05 PM
Changing the names of text boxes Changing the placeholder text for drop down boxes DeadBatteries Word 1 08-24-2012 09:09 AM
Changing the names of text boxes Arrows and text boxes disappear when changing view? Jesse Word 4 06-12-2012 05:28 PM

Other Forums: Access Forums

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