BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Latest Visio Version not handling VBA changing character size

Started by paulv45, April 20, 2022, 02:10:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


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.

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
End Sub
Visio 2019 Pro


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.
Sub reset_text()

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

End Sub


QuoteIf 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


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.


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?


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 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.
Visio 2019 Pro


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.

removed first upload. Replaced by new post.


@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
Visio 2019 Pro


1. Your code runs perfectly
2. In my upload I added a "runTextAppend" macro. Try running it.


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.
Visio 2019 Pro


What results are wrong?
The picture is the result of your macro applied to an arbitrary shape with text.


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.

Visio 2019 Pro


Update:  here's incorrect result even with <f8> single step.
Visio 2019 Pro


Ah!  Here's normal running of macro.  Result only caught 1st instance, ignored the rest.  Attached is screen capture and the file.
Visio 2019 Pro


So your upload again worked fine here.

Just a very silly try - because of this F8 thing - please add a DoEvents in the loop.

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 382 (show)
Files included: 32 - 1207KB. (show)
Memory used: 1247KB.
Tokens: post-login.
Cache hits: 15: 0.00161s for 26,765 bytes (show)
Cache misses: 4: (show)
Queries used: 16.

[Show Queries]