Can ChatGPT code VBA?

Dan_W

Well-known Member
Joined
Jul 11, 2018
Messages
1,943
Office Version
  1. 365
Platform
  1. Windows
Somewhat topical these days - I saw this today, and thought others might find it interesting.

 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I can comment that I have used it a little for VBA. It generally does what you tell it. I want to try recording a macro and telling it to simplify the code, to see if it can automate that process. For adding new features to existing code it is obviously hard composing the idea of the code for it to digest.
 
Upvote 0
Let's just say ChatGPT's use has been banned at StackOverflow for its propensity for the production of seemingly plausible (even correct) answers that are factually wrong. See: Temporary policy: ChatGPT is banned
The primary problem is that while the answers which ChatGPT produces have a high rate of being incorrect, they typically look like they might be good and the answers are very easy to produce. There are also many people trying out ChatGPT to create answers, without the expertise or willingness to verify that the answer is correct prior to posting. Because such answers are so easy to produce, a large number of people are posting a lot of answers. The volume of these answers (thousands) and the fact that the answers often require a detailed read by someone with at least some subject matter expertise in order to determine that the answer is actually bad has effectively swamped our volunteer-based quality curation infrastructure.
...
sanctions will be imposed to prevent users from continuing to post such content, even if the posts would otherwise be acceptable.
 
Upvote 0
Let's just say ChatGPT's use has been banned at StackOverflow for its propensity for the production of seemingly plausible (even correct) answers that are factually wrong. See: Temporary policy: ChatGPT is banned
I have some sympathy for that position, but I don't know how effective it will be. The answers it comes up with are deceptively confident. There was one the other day, @Macropod , on Reddit that you might find interesting - someone asked how to use VBA to convert a page in a Word document into a PNG or JPG file. Someone posted the response from ChatGPT (as below):

VBA Code:
Sub SavePagesAsJPEG() ' Declare variables
    Dim PageCount As Integer
   Dim i As Integer
   Dim FileName As String ' Get the number of pages in the document
   PageCount = ActiveDocument.ComputeStatistics(wdStatisticPages) ' Loop through each page
   For i = 1 To PageCount ' Set the file name for the current page
   FileName = "Page" & i & ".jpg" ' Save the current page as a JPEG file
    ActiveDocument.ExportAsFixedFormat OutputFileName:=FileName, ExportFormat:=wdExportFormatJPEG, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=i, To:=i 
   Next i
End Sub `

... which looks compelling.... but .... wdExportFormatJPEG ... what is this?!? o_O
 
Upvote 0
Interesting. I've been using ChatGPT for easy use-cases with a clear-cut question. For instance "Write code that removes all rows in a column which have either a value that is bold or is empty. Write it in VBA" and it produced the following

1672828095442.png


As you can see it left Sub, Dim and End Sub outside the actual code. So you may need a bit of experience to utelize it propperly since just copying the code would not work.

I later asked it "Edit the code so it works on the active column" and it gave me

1672828181034.png


Whilst it still left out Sub, Dim and End Sub it worked as intended. So for easier applications that can be fulfilled within a short span of code (low complexity, low risk of errors) it can be used quite efficiently.
 
Upvote 0

Forum statistics

Threads
1,223,947
Messages
6,175,562
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top