Visio Guy

Visio Discussions => Visio Bugs (er...Issues) => Topic started by: paulv45 on April 19, 2022, 09:10:55 PM

Title: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 19, 2022, 09:10:55 PM
My VBA code running forever has stopped working properly.

Anyone else having problems?

Perhaps someone could run this simple experiment that demos the problem on latest Visio version and runs correctly on earlier version.

Visio Version 2203 (Build 15028.20204)
Shape with text:0123456789 30 pt.
Shape sheet 1 character line.
Start recording.
Change 456 to 8 pt.
Stop recording.
Shape sheet 3 characters, 4 3 4, 30 8 30
Use ctrl-z to get back to all 30
Shape sheet back to 1 character line.
Run macro.
Observe all 8 pt.
Shape sheet 1 line 8.

Code
Sub Macro1()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Dim UndoScopeID2 As Long
    UndoScopeID2 = Application.BeginUndoScope("Font Size")
    Dim vsoCharacters1 As Visio.Characters
    Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(8).Characters
    vsoCharacters1.Begin = 4
    vsoCharacters1.End = 7
    vsoCharacters1.CharProps(visCharacterSize) = 8#
    Application.EndUndoScope UndoScopeID2, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub

***************************

Earlier version works properly.

Visio Version 2108 (Build 14326.20238)
Shape with text:0123456789 30 pt.
Shape sheet 1 character line.
Start recording.
Change 456 to 8 pt.
Stop recording.
Shape sheet 3 characters, 4 3 4, 30 8 30
Use ctrl-z to get back to all 30
Shape sheet back to 1 character line.
Run macro.
Observe correct -- 0123 30 pt, 456 8 pt, 789 30 pt.
Shape sheet 3 characters, 4 3 4, 30 8 30

Recorded macro looks identical to me.

Code
Sub Macro1()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Dim UndoScopeID2 As Long
    UndoScopeID2 = Application.BeginUndoScope("Font Size")
    Dim vsoCharacters1 As Visio.Characters
    Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(8).Characters
    vsoCharacters1.Begin = 4
    vsoCharacters1.End = 7
    vsoCharacters1.CharProps(visCharacterSize) = 8#
    Application.EndUndoScope UndoScopeID2, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub

Any help greatly appreciated.

Thanks.

Paul
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Paul Herber on April 20, 2022, 08:31:39 AM
I've reformatted your code section as it was getting corrupted by the bit that converts ( and : and ) etc into :o and  :-\ etc
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 20, 2022, 08:41:35 AM
I've reformatted your code section as it was getting corrupted by the bit that converts ( and : and ) etc into :o and  :-\ etc


You killjoy! That was the best part of the post.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 20, 2022, 09:45:12 AM
Visio Plan 2

Followed your instructions. Everything looks fine.
What is your point?
Help us helping you.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Paul Herber on April 20, 2022, 10:37:52 AM
I've reformatted your code section as it was getting corrupted by the bit that converts ( and : and ) etc into :o and  :-\ etc


You killjoy! That was the best part of the post.
I qu :-[ e a :( ee, I  :P a k :D j 8)
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 20, 2022, 04:40:24 PM
Thanks, Paul H.
Yacine -  are you saying you ran experiment on Visio Version 2203 (Build 15028.20204) and did not have a problem?  That is, characters after running macro you recorded were not all 8 pt?
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 20, 2022, 05:17:54 PM
Yes but visio Version 2102(Build 13801.21004)
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on April 20, 2022, 06:25:04 PM
/soapbox

MS continuing to introduce bugs to know good functions and capabilities
Curse of the west coast programmer ;-)

/!soapbox
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Surrogate on April 21, 2022, 01:42:47 AM
MS continuing to introduce bugs to know good functions and capabilities
Perhaps this is part of a strategy to migrate users of desktop versions of visio to Visio Plan 1 ?  :o
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on April 21, 2022, 07:27:17 AM
yea...but all that is is "same bugs / different platform"

It would make more sense if MS wants sunset visio...so they are poisoning usage.
Personally, I would think it would make more sense to add a few things to PPT and then say visio is going EOL
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 21, 2022, 01:16:00 PM
Vacine -- what version of Visio is Visio Plan 2 providing you?
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 21, 2022, 02:33:11 PM
Build 13801.21004
What are you trying to do anyway?
Why not a proper macro instead of the recorded one?
I suspect a layer 8 error because of the fixed reference to a shape.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 22, 2022, 01:11:43 AM
Running V2019 Pro, Windows 10.  I see the same problem.  Visio doesn't seem to be recognizing the Char.Begin / End settings correctly..  Definitely seems like a new bug.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 22, 2022, 01:57:26 PM
It occurred to me that perhaps the 1st step in the code ought to be setting the chars variable to null before assigning it the shape chars..  Just a thought.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 23, 2022, 12:25:31 AM
Took another look at this... Doing an <f8> step thru the code, it runs fine and provides the expected result.  Running the code, produces the error.  Interestingly, using debug.print does show that Begin / End statements do find the correct location for changes, but for some reason, at normal running, all characters are changed to 8 pt.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 24, 2022, 09:20:27 PM
Let's flog the dead horse.  So, I tried a different approach, modifying an old macro.  The macro steps thru all the characters in the shape text, one at a time, looking for a match to the desired text.
 The current version is shown below.  The code has some added debug.print statements, and a text style change.  Also, it acts upon a text string that has the word "the" in it twice.  Only the "the" should become smaller and bold font.

Single step executing the code using <f8> proceeds just fine, no issues.  The shape displays "the" as expected.  Resetting the shape to initial state, and running the code doesn't work.  The debug.print statements indicate that all of the code steps were executed, but the shape text is completely impacted, not just the "the"'s.

Code
Sub BoldnShrink()
    Dim vsoShp As Visio.Shape
    Dim vsoChars As Visio.Characters
    Dim strLen As Integer
    Dim i As Integer
   
    vsoMyText = "the"   'Enter desired text.
   
    Set vsoChars = ActiveWindow.Selection(1).Characters
    Set vsoShp = ActiveWindow.Selection(1)
   
    strLen = Len(vsoChars) - 1  'Length of entire shape text with "0" as starting count.
    txtLen = Len(vsoMyText)     'Length of desired text
    Debug.Print strLen
    Debug.Print txtLen
   
    For i = 0 To strLen         'Loop thru entire shape text
        vsoChars.Begin = i
        Debug.Print "i = ", i
        vsoChars.End = i + txtLen   'Check only char strings with same desired length
        If StrComp(vsoChars.Text, vsoMyText, vbTextCompare) = 0 Then
             vsoChars.CharProps(visCharacterStyle) = 17#     'Set to bold.
             vsoChars.CharProps(visCharacterSize) = 14#
             Debug.Print vsoChars.Text
       End If
    Next
End Sub
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 25, 2022, 02:00:43 AM
I'm a little bit slower than you guys.
Correct me if I'm still wrong.
The O.C.'s problem is that the rows in the characters section don't disappear when a row's formatting is reset to original.
Visio seems to go a lazy way of not re-uniting the rows if they are identical. I don't think it is a new phenomenon, nor that it is a bug. It works fine.
You can nevertheless reset the text by deleting and re-inserting it.
Code
Sub reset_text()

    Set shp = ActiveWindow.Selection(1)
    temp = shp.Text
    shp.Text = ""
    shp.Text = temp

End Sub
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 25, 2022, 05:30:00 AM
Quote
If Visio had been developed some 10-20 years later, the developers would surely have chosen an HTML representation for formatting.
You would then have had an HTML string in a cell of the shapesheet and much easier ways to format your text using code.

... Confucius, book of the Raising Dragon, chapter "A scale's colours". :D
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 25, 2022, 07:34:46 AM
Yacine -- apologies for missing your your earlier post where you supplied full Visio version info -- my bad.

I have two systems where I am running my code.
System A is Plan 2.
It was (4/15/2022):
Visio Version 2108 (Build 14326.20238)
But it looks like some time between 4/15/2022 and 4/25/2022 it has autoupdated to:
Visio Version 2203 (Build 15028.20228)
with this update, the problem has propagated to System A.  Bummer.
Noting you are currently:
Visio Version 2102(Build 13801.21004)
My guess is that if you update your Plan 2 install, you will likely experience the problem

With regard to why using a recorded and not a proper macro (4/21).
This is a case of what is the simplest thing I can do to see if others can duplicate the problem.

Clarifying what I am trying to do:
In my real world I am taking the an existing shape, appending 4 characters to the existing text, then setting the font of the added text to 8 pt leaving the existing whatever font size it was.
This has been working fine for multiple years and now fails.

Will look at your reset_text suggestion.
 
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 25, 2022, 08:42:14 AM
wapperdude -- Thanks for jumping in here.
Am I correct that you have duplicated the problem using the steps I supplied?
If so, at least I'm not totally nuts.
Making sure we are on the same page -- what are the Visio version details you are seeing?
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 09:05:56 AM
Yes.  I did encounter same problem.  Then tried using a previously working macro, my most recent post, and it too no longer works.

However, using the <f8> key to step thru the macro line-by-line, both codes seem to execute properly.  Adding debog.print statements to code verifies that under normal execution, all lines do execute properly.  So, not sure if this is a Visio or a Windows update induced issue. I'm using desktop version.

Note...1) you can take the code I most recently provided, change the line for desired text, from "the" to "456", and it will run with your test case.  I only reduce the text to 14 pt.

2) either add a new shape or modify existing shape and enter any text.  As long as " the" exists at least once in the text string, the code will make the change...at least it will if you step thru usingb<f8>.. 

3) it would be interesting to see if other forum users actually experience this issue with various versions of Visio.  It's a simple, quick test.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 25, 2022, 10:23:56 AM
Hi Paulv,
I set up a form which allows to append text to shapes.
Run it, set the checkbox to true, then everytime you change the window's selection the text gets added to the shape (or many) and is formatted.


PS
removed first upload. Replaced by new post.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 11:02:30 AM
@Yacine:  I could not get the "form" to launch, nor could I get the code to run.  However, did you try the code provided?  It is an important closure point as it might indicate whether the issue is local or global.  Thanks
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 25, 2022, 11:09:10 AM
@Wapperdude,
1. Your code runs perfectly
2. In my upload I added a "runTextAppend" macro. Try running it.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 11:53:19 AM
Well, that's interesting.  The "append" form does work and appends text.  The form that executes my macro, does run, and does run the macro.  But the results are totally wrong.  However, using the <f8> step method all is well.

Guess, next stop, the reinstall Visio method.  Ugh.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 25, 2022, 12:53:12 PM
What results are wrong?
The picture is the result of your macro applied to an arbitrary shape with text.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 04:59:16 PM
There is no predictable pattern...except when I single step thru the code.  Then, the code does what's intended.  But if I just let the code run, either what I supplied or that which the OC provided, then the results are wrong.  I've seen the entire text stream reduced in size.  In the case of my code, I've seen size reduction but no bold style implemented.  I've seen wrong letter, e.g., just the 1st 3 letters.  In all cases, the debug.print shows correct reporting.  Also, whether the shapesheet is open or closed has no influence one way or the other.

When execution is correct, shapesheet shows multiple rows in the Character section.  When results are wrong, not to the code, the Character section merely has a single row (when the entire string is uniformly changed).  I didnot check the SS for the case where there was a non-uniform change.



Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 05:07:04 PM
Update:  here's incorrect result even with <f8> single step.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 25, 2022, 05:14:37 PM
Ah!  Here's normal running of macro.  Result only caught 1st instance, ignored the rest.  Attached is screen capture and the file.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 26, 2022, 01:12:31 AM
So your upload again worked fine here.

Just a very silly try - because of this F8 thing - please add a DoEvents in the loop.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 26, 2022, 09:28:38 AM
Worth a try.  I don't believe it to be an issue since the simpler code without the loop also experienced same difficulties.  As it works fine on your setup, I'm suspecting a local corruption of some sort.  It would be nice to find something definitive to provide to the OP.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 26, 2022, 02:38:14 PM
Thanks for helping here Yacine & wapperdude.

I'm looking at finding an immediate term solution while ultimately seeking a long term solution.

I think we have clearly identified a bug in the latest Visio release.
The long term solution is to see if we can (A) get MS to fix or (B) develop a workaround.

In the immediate term I took a look at downgrading to an earlier version and found:
https://support.microsoft.com/en-us/topic/how-to-revert-to-an-earlier-version-of-office-2bd5c457-a917-d57e-35a1-f709e3dda841
Following the relatively simple steps there I successfully loaded: Visio Version 2108 (Build 14326.20238)
This fixed the problem in my ultimate application.  I was not surprised, but pleased.  We are on the right track.
If you try this note the xxxxx.yyyyy in the config file is the build ID -- 14326.20238
So the line is:
<Updates Enabled="TRUE" TargetVersion="16.0.14326.20238" />
The build ID is specific to Visio and you will not find it in the reference doc.
Also in the reference doc is says turn off updates in Outlook, but I did this in Visio.

So this was successful on my System B.
I have a more complicated environment on my System A and that's my next step and will report here when get that working.

Then on to the long term solution.

Looks like you are working the workaround approach.  Thanks for that.

Any idea if we could get MS to look at problem introduced in latest release?
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on April 27, 2022, 08:36:17 AM
good luck with A) !!!   >:(

MS spends more time introducing bugs and depreciating functions than fixing bugs and adding new (useful) functions
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 27, 2022, 02:25:24 PM
@Yacine:
  >. Tried the DoEvents to no avail.
  >  Did Visio uninstall /re-install.  That didn't help either
  >. Tried a delay timer at a couple different code locations.  No help.

So far, no techniques have yielded a correct code execution. 
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 27, 2022, 04:53:08 PM
wapperdude -- wondering if you looked at the version details and tried the install earlier version noted in my last post.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 28, 2022, 01:55:23 AM
@Paulv,
Pardon the heretical question, but would it be thinkable to switch to a "right" implementation? ;)
What I mean is that text formats are a quite fragile way of storing data (as you are just experiencing).
A better place for data are prop fields. You can insert them as fields and still do your formatting as needed.
A macro could transform all the existing shapes in one go and you would end up with a much stronger structure.
... just my 2 cents. I will understand if you first reject categorically this idea, but you may spend some minutes on it.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on April 28, 2022, 11:04:28 AM
@Yacine:
Certainly want to go to the higher ground solution, but I have working code in several places that I need to fix, test, etc.
It's a time to solution issue -- immediate term and long term.
Am working immediate term on my System A at the moment.  Then onward.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on April 28, 2022, 11:46:56 AM
I noticed in Wapperdude's screenshots that the first instance was in both cases properly formatted.
If this is everytime true, them maybe there is something with the characters object being corrupted when modified.
I can't try it by myself, since I don't get the errors, but would you guys try to re-instantiate this object after each modification?
To explain:
not:
  set o_chars = shp.characters
  for i = ...
    pos = find
    o.chars = begin...

but:
  while find = ...
    o.chars = shp.characters
    o.chars ...

in other words move the set allocation inside the loop.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 28, 2022, 06:11:59 PM
@Yacine: 
So, after being more methodical, I noticed that the Chars section must start with a single row setup.  The macro only acts on 1st row.  That was creating some of the inconsistent results. 

Once, a correct starting condition is defined, then the <f8> approach always works correctly.  Stepping thru the code, you can watch as each "the" is made bold, then resized, and then moves to next "the".  Normal code execution also provides consistent, identical response.  Namely, ALL text is bold and shrunk to the new size.

Looking at shapesheet, the <f8> single line execution produces multiple rows in Char Section.  This would be the expected, correct behavior.  With the normal execution mode, only a single line is present with new values for Style and Size.  The single affects the entire text string.

Your comment about messing up the Char string, might be a possibility, if, somehow the indexing gets clobbered...like when iteratively deleting a bunch of shapes.  Will try starting at end of string and work backwards to the beginning.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on April 28, 2022, 06:32:54 PM
Other than being a little weird, there were no result changes by stepping backwards.

About reinstalling. .. I did uninstall, then cleaned registry.  The installation file says "office", and does access the web as it prepares the installation.  I'm wondering if that includes all available updates.  I get no notice of needing office updates.  Plus, the addins, e.g., Paul's Super Utilities, and others are also reinstalled.  So, it doesn't seem like I'm back to original config.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 03, 2022, 08:35:46 PM
I am continuing to struggle getting my System A to load the earlier version.
I'm guessing I am experiencing the same thing as wapperdude.
It acts like downloading the earlier version but doesn't seem to.
Going to try on system with no Visio installed, just downloading the earlier version.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 06, 2022, 11:06:37 AM
Here's my latest experience...
The latest release of Visio:
Version 2204 (Build 15128.20178)
Fixes the problem in the simple demo but my code still fails.
Would be interested in your experience, wapperdude.
Before trying to develop another simple test to show issue, planning to look more closely at Yacine's suggestion.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 07, 2022, 08:27:51 PM
Continuing to beat on this with no success.
Like wapperdude, if I put a break before
objChar.CharProps(visCharacterSize) = 8#
and then execute with <f8> life is good.   The 4 characters are set to 8 per Begin and End.
If I just let it run with no break, all of the text is set to 8.
I've tried screen update off/on and timer function -- no success.
MsgBox before the CharProps line requiring user response works too but is pretty brutal.
So far only Break and MsgBox avoid the problem introduced some time after 2108.
I am baffled by this behavior.

A fun fact -- in a 2108 experiment I accidentally set begin and end after last character in text and this exhibited bad behavior -- all char in text to 8.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 07, 2022, 08:29:12 PM
@Yacine
It seems your code also runs fine for me.
Also, I don't understand how prop fields would play.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Yacine on May 08, 2022, 08:57:54 AM

Also, I don't understand how prop fields would play.

The whole text would be split into its main components.
prop.main_text = "so and so"
prop.extra_data = "xyz 123"
and you would insert those field into the shape's text.
You would also protect the text, so users don't overwrite the fields.
The second field you be formatted bold and whatever.


You can get fancy with those fields if you object, that users absolutely need to enter the main text in the shape directly.
Then you would unprotect the text, but hide it. The text would then be written to a sub-shape (not hidden).

Second possible objection: you have tons of drawings based on the old method.
prepare a master with the 2 a.m. props.
iterate over all the shapes and replace them by the new master - now the props are available - and write the text of the shape into the main prop. The second one could be parsed by means of checking the rows of the char section.

This all may sound complicated - I agree. At the end it will still be more robust.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 09, 2022, 09:17:45 PM
Wondering if others could suggest fixes related to runs when stepping using <f8> I posted in Programming & Code:
What does in mean when code runs in debug but not in operation?

Yacine also responded there suggesting (as also in this thread) DoEvents before and after:
objChar.CharProps(visCharacterSize) = 8#
Tried both before and after and that worked.  Just before also works. Just after does not.

So conclusion is that something deep down in Visio did indeed change some time after 2108 -- not really a bug, just a change.
And we have a fix.

I'll continue to work to be sure everything is solid, but pretty confident it is.  Will report back if not.

Thanks so much for hanging in there with me on this Yacine and wapperdude.  Your help is very much appreciated.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on May 10, 2022, 07:15:39 AM
One suggestion would be to move the scaling out of this

user.scale = width/predefined width.     

For example, lets say the idea with is 20mm....then user.scale = width/20mm....if width 20mm....the char is 8pt * 2

Character = 8pt * user.scale

So if you want to change the font scale, your vba could modify or replace the value in user.scale without touching the char cell

Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on May 10, 2022, 11:44:41 AM
@Vojo:  the reason for touching the char.size cell was to only change specific characters within the string, not the entire string.

@ Yacine, paulv45:  retried the DoEvents, both the original macro and my looping macro.  Both failed to work correctly with DoEvent functions.  Note, the only time it works presently is during the record macro phase.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on May 11, 2022, 07:16:27 PM
Tried something different, for sanity check.  After setting char begin & end, instead of using '.charProps(...)' , I used  '.Text = "NewTxt"'.  This replaces the portion of the text string identified by the begin/end value assignment with NewTxt.  That works fine.  Then I added another line, using char props to make new text bold.  All text became bold.

Looking at shapesheet, there's only the single row in the Characters section.  Visio isn't doing any parsing.  Oh. Plus, Visio doesn't allow you to manually add rows to this section.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on May 12, 2022, 09:15:25 AM
isnt charsize for ALL characters?

are you suggest some sort of group if child shapes, each one wih 1 character?

I am not aware of 5 char. size cells for "hello" in 1 shape,,,nor how to map each to a char (1st to 1st?)
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on May 12, 2022, 10:46:51 AM
The Characters section of shapesheet holds all manner of formatting of text. 
Typically, the formatting is applied to the entire text string.  Indeed, when you add text to a shape, there is but a single row in this section, and what might, euphemistically, be called the row name, indicates the character count. 

But, if you identify a portion of the string, i.e., a single letter, a word, or a group of words, you can create a "localized" formatting for the selection, e.g., make it bold, different color,.  When such localized for mating occurs, Visio adds one or more rows to the the character section.  Each row signifies the appropriate formatting applied to the number of characters in that row.

This is easily demonstrated.  Put a shape on drawing page, open shapesheet, and arrange both windows for viewing.  Scroll to the Character section to view it.  Now, enter some text into the shape, and the row fills in.  Select a word and make it bold.  Watch Visio add rows, change text properties/formatting.   

Doing this programmaticly is the heart of this discussion.  It is a process that both myself and the OP have successfully used in the past, but now fails.  Yacine has not encountered the problem, but suggested a "fix".  The fix seems to work for the OP, but not for me.  All of this used to work until recently.  Something has changed.

The mechanism for doing this is easily obtained using video recorder...and in that mode, it works for me.  There is also code postings above.  I've included code posts that step thru the entire text string, searching for all occurrences of a specified character combo.  The localized portion of the string is established by the char.begin and char.end fcns, and applied using char.props method.  See:
https://docs.microsoft.com/en-us/office/vba/api/visio.characters.begin (https://docs.microsoft.com/en-us/office/vba/api/visio.characters.begin)
https://docs.microsoft.com/en-us/office/vba/api/visio.characters.charprops (https://docs.microsoft.com/en-us/office/vba/api/visio.characters.charprops)

So, no grouping employed.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: vojo on May 12, 2022, 01:15:30 PM
ok...works...but kludgy
- its based on groups of characters
      For example " hello" would have 3 rows
          Row 1 for he
          Row 2 for LL
          Row 3 for o
       so basically its along the line of "changes in character format==>new row"
- since no directly specified linkage, some body would need a master shape with each character called out.
       in this example,  5 rows...always know its five so "XXXXX"
          Then could program row 3,4 as appropriate....e.g  "XXXXX"...dont know how to programitcally pick chars 3,4 to force row calculus to allow program changes for those characters.

bottom line:  great for UI...butt tough programmatically

maybe thetext = user.1+user.2+user3+user.4+user.5....maybe that would trigger 5 rows
Oherwise...group of child shapes
         
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on May 12, 2022, 02:42:17 PM
Actually, not that tough to do coding.

For instance, my code loops thru the string to search for something and then edit what you find.

If you have a multi-formatted string, you loop thru the rows of the section and then do what you want.

For more code examples:  http://visguy.com/vgforum/index.php?topic=7638.msg32400#msg32400 (http://visguy.com/vgforum/index.php?topic=7638.msg32400#msg32400)
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on May 14, 2022, 01:09:25 PM
Based on further experiments and wapperdude's work, I am not convinced that
simply adding DoEvents before every CharProps call will always work.

Conclusions so far...

- Based on wapperdude and my experience there is a bug manifesting itself
   in the handling of the Characters.CharProps property.

- This bug was not present in the 2108 release and in releases prior to that.

- Can't say when it was introduced, but exists in 2203 and 2204 releases.

- While the bug exhibits itself in Characters.CharProps property, it seems
   likely that a change someplace else causes CharProps to behave badly.

- The behavior is subtle and we do not yet have a simple test case.

- In one example adding DoEvents prior to Characters.CharProps solves the
   problem.

- It is likely that given sufficient time a simple test case can be created.

- Evidence of the problem shows up in the Character rows of the ShapeSheet.

The burning questions...

If we were able to make Microsoft aware of the problem would it likely be fixed?

If so, what is the mechanism to make Microsoft aware of the problem?

Any thoughts?

Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on June 02, 2022, 10:30:16 AM
@wapperdude
@yacine
I was a bit surprised at no responses to my last post.
I am assuming in fact there is no way to report a problem to MS with any hope of fixing.
I am proceeding with DoEvents before Characters.CharProps calls with hope this always work (thanks again yacine).
Thanks to both of you for helping me.
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: Surrogate on June 02, 2022, 10:42:02 AM
I am assuming in fact there is no way to report a problem to MS with any hope of fixing.
I know few ways:
1. feedbackportal.microsoft.com (https://feedbackportal.microsoft.com/feedback/forum/42d29dfb-3e1c-ec11-b6e7-0022481f8472),  there you can leave your wishes and suggestions. if your appeal is supported by many users - MS [probably] will try to implement it.
2. In the Visio team's blog entries, they indicate the e-mail: tellvisio@microsoft.com.
3. If you use Visio Plan 2, in the interface you can find a button with a smile to send your message: sad smiley - report a problem
(https://support.content.office.net/en-us/media/dbe27ae5-8f0b-42e6-89c7-e5b9dfc232a8.png)
Title: Re: Latest Visio Version not handling VBA changing character size
Post by: paulv45 on September 01, 2022, 03:33:43 PM
@Surrogate
@wapperdude
@yacine
Sorry I have been silent.
Thanks for jumping in, Surrogate.

In my project log it looks like I did use the Feedback machinery to make input to MS 4/29/2022.
Heard nothing back.
Don't know if related, but I happy to report for me the problem is resolved in 2207.
Hope it stays fixed.

wapperdude, you might want to give it a check for your app.

Paul

Title: Re: Latest Visio Version not handling VBA changing character size
Post by: wapperdude on September 01, 2022, 08:57:19 PM
Thank you for getting back to us.  Yes.  The new update seems to have fixed the problem.  The code runs fine now.

Cheers!