+ Reply to Thread
Results 1 to 5 of 5

Excel UserForm Label AutoSize problem - cropping Captions

  1. #1
    Registered User
    Join Date
    11-07-2018
    Location
    Shetland
    MS-Off Ver
    2007
    Posts
    13

    Excel UserForm Label AutoSize problem - cropping Captions

    Hi,

    I'll see if I can describe this properly. I am experiencing strange behaviour in Excel 2007 where the AutoSize property of Labels seems to be causing some of the Label's Caption not to be displayed.

    I have a UserForm that displays guidance/recommendations after another UserForm is completed/submitted. The guidance UserForm has 4 labels and their captions are set to different text strings depending on the values set by the first UserForm. Because the text strings are of varying lengths and because there is no built-in way to centre Caption text vertically in a Label (and because I want things to look nice) I have used the following VBA to set the string, autosize the inner label and then centre the inner label on the outer label:

    Please Login or Register  to view this content.
    NB - The background colour of both Labels should be the same colour, but I have temporarily changed one to white to see the border/size of the inner label

    The size of the outer Label is W: 366, H: 54. The typeface used is Tahoma.

    What happens with the code as above is that blocks A, B and C of the caption string display on one line, but block D does not display at all. There is clearly enough room for it to display on one line. It does display the whole string if you reduce the string by one character ("A0123456789 B0123456789 C0123456789 D012345678") and, crucially, it does display the whole string when you lengthen it - this displays this string: "A0123456789 B0123456789 C0123456789 D0123456789 E" on one line. Longer strings, including those which need to be / should be displayed over more than one line, seem to display without problems.

    Most of my strings are longer than this and don't encounter any issues, but one of them seems to fall in this Twilight Zone; the last few words are not displayed. I could probably re-word the text to avoid the issue, but I would rather work out out what's going on.

    Any ideas?

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Excel UserForm Label AutoSize problem - cropping Captions

    Alter your centralising code.

    Please Login or Register  to view this content.

    regards.
    torachan

  3. #3
    Registered User
    Join Date
    11-07-2018
    Location
    Shetland
    MS-Off Ver
    2007
    Posts
    13

    Re: Excel UserForm Label AutoSize problem - cropping Captions

    Hi torachan,

    Thanks for the reply - sorry, I've been away and not checking the thread.

    I tried your edit and it placed the text off-centre to the left, although it did display all the text! I don't see why you would divide by 2 again when calculating the horizontal position - it gives half the offset you need to centre the inner label. I follow the logic of the rest of your suggestion (though it seems to be just a different way of getting to the same offsets that result from my original code). I removed the last /2 from the horizontal offset part of your code and it produced the same results I was getting - a centralised label, but cropped text.

    The only thing that has worked for me was to adjust the starting sizes of the inner (before autosizing). I managed to find a size that doesn't produce this error, but I am none the wiser as to why it should occur in the first place...

    Thanks again

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Excel UserForm Label AutoSize problem - cropping Captions

    Hi.
    The puzzle got worse before it got better.
    I kept losing the inner label, then a light bulb moment the 'Zorder'.
    This gave priority to the inner label coming to the fore and the white label to the back.
    Fore some reason ???? I needed to set 'wordwrap' to false then reset to true in the code.
    I put a couple of extra blocks in the 'caption' string to check the 'wordwrap'
    The pieces of code iterated out were used to see what was happening.
    After all nothing wrong with your positioning code.
    torachan.
    attached file is what finally worked.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-07-2018
    Location
    Shetland
    MS-Off Ver
    2007
    Posts
    13

    Re: Excel UserForm Label AutoSize problem - cropping Captions

    Hi Torachan,

    Thanks again for persevering with this. I ended up setting the sizes manually for the problematic instances. I will play around with the zOrder and see if I can get it to work - it'll be good to get my head round what's happening here.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help searching for a row, then label captions using row data
    By radabm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-09-2017, 06:34 PM
  2. Vlookup Multiple answers and place in label captions
    By jamie030489 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2015, 11:09 AM
  3. [SOLVED] Counting 2 label captions on userform
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 02:49 AM
  4. Change label captions based on combobox selection
    By alter54 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-07-2012, 06:02 PM
  5. Format label captions
    By Stuie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2006, 02:49 PM
  6. rename label captions
    By jinx_uk_98 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-20-2005, 05:45 PM
  7. cell values as label captions
    By Rbp9ad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-10-2005, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1