Author Topic: Latest Visio Version not handling VBA changing character size  (Read 4568 times)

0 Members and 1 Guest are viewing this topic.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #15 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
« Last Edit: April 24, 2022, 09:22:16 PM by wapperdude »
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #16 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
« Last Edit: April 25, 2022, 02:04:38 AM by Yacine »
Yacine

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #17 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
« Last Edit: April 25, 2022, 05:40:08 AM by Yacine »
Yacine

paulv45

  • Jr. Member
  • **
  • Posts: 52
Re: Latest Visio Version not handling VBA changing character size
« Reply #18 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.
 

paulv45

  • Jr. Member
  • **
  • Posts: 52
Re: Latest Visio Version not handling VBA changing character size
« Reply #19 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?

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #20 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.
« Last Edit: April 25, 2022, 09:17:49 AM by wapperdude »
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #21 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.
« Last Edit: April 25, 2022, 11:10:44 AM by Yacine »
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #22 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
« Last Edit: April 25, 2022, 11:10:05 AM by wapperdude »
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #23 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.
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #24 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.
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #25 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.
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #26 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.



Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #27 on: April 25, 2022, 05:07:04 PM »
Update:  here's incorrect result even with <f8> single step.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4399
  • Ideas Visio-lized into solutions
Re: Latest Visio Version not handling VBA changing character size
« Reply #28 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.
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2984
Re: Latest Visio Version not handling VBA changing character size
« Reply #29 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.
Yacine