Using ChatGPT to write VBA code for Visio app

Started by Surrogate, March 10, 2023, 12:01:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Surrogate

We can find many videos of using ChatGPT to get formulas and VBA code for MS Excel:
e.g. great Leila Gharani in her video "How ChatGPT Can Help With Your Complex Excel Spreadsheets"

Do any of you have experience using ChatGPT to write VBA code for Visio and ShapeSheet formulas?
Please share your insights :)

I previously brought up a similar topic in the Russian-speaking community of Visio users

Paul Herber

Taking into account the answers that ChatGPT has given me on other subjects I wouldn't trust its answers as far as I could shove it!
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Thomas Winkel

Funny, I tried that a few days ago and find the results impressive:


VBA code that lists all shapes in a visio document where Prop.Name eqals "Hello":


Sub ListShapesWithPropNameHello()

Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape

For Each vsoPage In ActiveDocument.Pages
    For Each vsoShape In vsoPage.Shapes
        If vsoShape.CellExistsU("Prop.Name", 0) Then
            If vsoShape.CellsU("Prop.Name").ResultStr(visUnitString) = "Hello" Then
                Debug.Print vsoShape.Name
            End If
        End If
    Next vsoShape
Next vsoPage

End Sub

Very cool, only replace visUnitString with visNone.


A Visio ShapeSheet formula that returs "large" if Prop.Size is greater than 20 and otherwise User.Value:


=IF(Prop.Size > 20, "Large", User.Value)

Perfect :)

I see it a bit like the macro recorder.
Not very helpful, but sometimes I have a look what it does.

Imagine what is possible in 10 years  :o

Thomas Winkel

I attach a screenshot to view the settings.
"text-davinci-003" gives much better results as the "code-davinci" models.

Visisthebest

Can ChatGPT write new features for Visio desktop for Microsoft? Then we can get new stuff in Visio desktop, finally!
Visio 2021 Professional

Yacine

#5
Have been playing with it for a while too, but it did not occur to me to think about Visio for it too (old man, too many brain cells already lost ;) ). Thanks Surrogate.

Here are some thoughts from my very own perspective.


       
  • I did not suspect that it knows Visio too, since our "hobby" is very "niche".
  • Writing routines similar to what Thomas provided is rather boring (sorry Thomas, no offence meant). That would be stuff for beginners, not people understanding the object model.
  • An immense help would however be a code translator from Python to VBA - actually easy, but I haven't seen that yet. To explain myself: The beauty of python - as I perceive it - is that I can setup variable structures on the fly like "L = [[shp, shp.ID, shp.Cells('PinX').ResultIU] for shp in ActivePage.Shapes if shp.CellExists('prop.A',False)]" - This would give me a list of lists. The inner lists holding a shape as object, its ID and in this case its PinX. In VBA I would need for this 1-liner to declare an array (as variant), a temporary var for traversing the collection, a for loop, an IF statement, a REDIM statement, the whole thing twice since I'm collecting the shapes and their IDs, and so on. Another great feature are functions that return several results. In VBA "practically" impossible to implement (because of crapy array functions). So here it is, not so much the help with Visio, but to leverage the insufficiencies of VBA.
  • Visio solutions must always consider the different tools that Visio offers - the shapesheet, templates, stencils, macros, addins, external data sources. Only when having considered this whole arsenal of "weapons" a solution can be good. I wonder how good ChatGPT would handle this complexity. Worth being tested.
Yacine

Yacine

#6
Quote from: Visisthebest on March 11, 2023, 11:41:28 AM
Can ChatGPT write new features for Visio desktop for Microsoft? Then we can get new stuff in Visio desktop, finally!

How would that be possible? Reverse engineer an application, modify it, rewrite the code and compile?
Very imaginable, but not in 2023!
;)


Think about all the copyright issues. That would be the end of M$ and the like.


But may be I understood you wrong.
Yacine

Yacine

Quote from: Thomas Winkel on March 11, 2023, 11:07:15 AM
I attach a screenshot to view the settings.
"text-davinci-003" gives much better results as the "code-davinci" models.
What is that screenshot? My interface looks different. Can you send a link?
Yacine

Thomas Winkel

Quote from: Yacine on March 11, 2023, 01:41:25 PM
What is that screenshot? My interface looks different. Can you send a link?
https://platform.openai.com/playground

I was also surprised that ChatGPT is able to generate code for Visio because I thought that this is too specific.
But I think that it is very far away from being really helpful.
Maybe this could be integrated into IDEs to suggest code snippets while the user is typing.
But absolutely impressive, anyhow!

Thomas Winkel

#9
Another thought:
I can imagine a use case for the end user in not so far future.
Imagine MS would integrate that in Office while completely abstracting away code, formulas and all those complicated stuff.
The user would only formulate his request and Office would suggest a result (not a solution).
The user can accept or specify more precisely or rephrase the request or cancel.

I think this will be much more helpful for the standard user as the macro recorder is.
And with the results above in mind I bet that in a few years such a tool could solve many simple automation tasks in acceptable quality.

Paul Herber

ChatGPT doesn't generate code, it copies it from elsewhere.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Paul Herber

Quote from: Thomas Winkel on March 11, 2023, 06:22:32 PM
The user would only formulate his request and Office would suggest a result (not a solution).

I'm sorry, Thomas. I can't do that.
;D
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Thomas Winkel

Quote from: Paul Herber on March 11, 2023, 06:24:40 PM
ChatGPT doesn't generate code, it copies it from elsewhere.
Agree that it doesn't generate, but it's more than a copy. Maybe something between copy and create.
But to be honest, I also copy a lot of StackOverflow when programming  ;D

Quote from: Paul Herber on March 11, 2023, 06:26:08 PM
I'm sorry, Thomas. I can't do that.
;D
;D
Would be a huge improvement if ChatGPT would be able to refuse, it always pretends a solution.
Here to take over the world:


VBA code to take over the world:


Sub TakeOverTheWorld()

Dim i As Integer

For i = 1 To 100
    Call LaunchMissiles()
    Call EstablishMilitaryDictatorship()
    Call EstablishGlobalCurrency()
Next i

End Sub

8)

Paul Herber

You forgot:

  Call DeployExpendableMinions()
  Call KillBondJamesBond()

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

wapperdude

#14
Y'all must be smokin your socks.  While what you've suggested as possible "calls", with the exception of Paul's kill call, which is neither possible (latest movie is clearly fictional), nor practical as it would require all of the preceding, but futile, calls.

It would seem that ultimately you have a call for each line of code.  And if the call refers to a more complex function, then that too could have an extraordinary number of calls.  I can see it now...error handler..." The line you called is busy.  The average wait time is 30 minutes.  Would you like to wait, or leave a call back number?"

I can hardly wait for the future!  Long live James Bond!  🤔😖😜    🤓🤓🤓
Visio 2019 Pro