Write a vba code for generate v ai like chatgpt. it give all responses in excel.don't show any source data . if want to show source press alt+k to show source . get data from web but not show any website .create a button in middle of the screen show v ai. if press by someone then ask what is your name. if enter name. then ask what can i do for you. if want to quit then just type i want to quit
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's an enhanced VBA solution with centered button positioning and improved JSON parsing:
vba
' Place in ThisWorkbook module
Private Sub Workbook_Open()
CreateButton
Application.OnKey "%k", "ToggleSourceData"
End Sub
' Place in a standard module
Sub CreateButton()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
On Error Resume Next
ws.Buttons("V AI").Delete
On Error GoTo 0
' Get window dimensions
Dim winWidth As Double
Dim winHeight As Double
winWidth = ActiveWindow.Width
winHeight = ActiveWindow.Height
' Button dimensions
Dim btnWidth As Double
Dim btnHeight As Double
btnWidth = 100
btnHeight = 30
' Calculate centered position
Dim btnLeft As Double
Dim btnTop As Double
btnLeft = (winWidth - btnWidth) / 2
btnTop = (winHeight - btnHeight) / 2
' Add button
Dim btn As Button
Set btn = ws.Buttons.Add(Left:=btnLeft, Top:=btnTop, Width:=btnWidth, Height:=btnHeight)
With btn
.Caption = "V AI"
.Name = "V AI"
.OnAction = "Button_Click"
End With
End Sub
Sub Button_Click()
Dim userName As String
userName = InputBox("What is your name?", "V AI")
If userName = "" Then Exit Sub
Dim query As String
query = InputBox("What can I do for you?", "V AI")
If LCase(query) = "i want to quit" Then
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = "Goodbye, " & userName & "!"
Exit Sub
ElseIf query = "" Then Exit Sub
Dim response As String
response = GetWebData(query)
StoreSourceData response
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = response
End Sub
Function GetWebData(query As String) As String
On Error Resume Next
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "https://api.quotable.io/random?tags=" & query, False
http.send
If http.Status = 200 Then
Dim responseText As String
responseText = http.responseText
' Improved JSON parsing
Dim contentPart As String
contentPart = Split(Split(responseText, """content"":""")(1), """")(0)
GetWebData = "AI Response: " & contentPart
Else
GetWebData = "Error connecting to server"
End If
Set http = Nothing
On Error GoTo 0
End Function
Sub StoreSourceData(data As String)
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets("SourceData")
On Error GoTo 0
If ws Is Nothing Then
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "SourceData"
ws.Visible = xlSheetVeryHidden
End If
ws.Range("A1").Value = data
End Sub
Sub ToggleSourceData()
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets("SourceData")
On Error GoTo 0
If Not ws Is Nothing Then
ws.Visible = IIf(ws.Visible = xlSheetVisible, xlSheetVeryHidden, xlSheetVisible)
Else
MsgBox "No source data available", vbInformation
End If
End Sub
Key improvements:
Button is centered on the active window
Better JSON parsing for quote content extraction
Cleaner response formatting
Error handling for API requests
To use:
Press Alt+F11 to open VBA editor
Create a module and paste the code
Save as .xlsm and reopen to activate
The button will now appear centered in your Excel window. Responses will show in cell A1, and you can toggle source data visibility with Alt+K. The API call uses a public quote service for demonstration.
User
Write a vba code for generate v ai like chatgpt. it give all responses in excel.don't show any source data . if want to show source press alt+k to show source . get data from web but not show any website. first question ask what is your name. if enter name. then ask what can i do for you. if want to quit then just type i want to quit
Assistant
Here's an enhanced VBA solution with centered button positioning and improved JSON parsing:
vba
' Place in ThisWorkbook module
Private Sub Workbook_Open()
CreateButton
Application.OnKey "%k", "ToggleSourceData"
End Sub
' Place in a standard module
Sub CreateButton()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
On Error Resume Next
ws.Buttons("V AI").Delete
On Error GoTo 0
' Get window dimensions
Dim winWidth As Double
Dim winHeight As Double
winWidth = ActiveWindow.Width
winHeight = ActiveWindow.Height
' Button dimensions
Dim btnWidth As Double
Dim btnHeight As Double
btnWidth = 100
btnHeight = 30
' Calculate centered position
Dim btnLeft As Double
Dim btnTop As Double
btnLeft = (winWidth - btnWidth) / 2
btnTop = (winHeight - btnHeight) / 2
' Add button
Dim btn As Button
Set btn = ws.Buttons.Add(Left:=btnLeft, Top:=btnTop, Width:=btnWidth, Height:=btnHeight)
With btn
.Caption = "V AI"
.Name = "V AI"
.OnAction = "Button_Click"
End With
End Sub
Sub Button_Click()
Dim userName As String
userName = InputBox("What is your name?", "V AI")
If userName = "" Then Exit Sub
Dim query As String
query = InputBox("What can I do for you?", "V AI")
If LCase(query) = "i want to quit" Then
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = "Goodbye, " & userName & "!"
Exit Sub
ElseIf query = "" Then Exit Sub
Dim response As String
response = GetWebData(query)
StoreSourceData response
ThisWorkbook.Sheets("Sheet1").Range("A1").Value = response
End Sub
Function GetWebData(query As String) As String
On Error Resume Next
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "https://api.quotable.io/random?tags=" & query, False
http.send
If http.Status = 200 Then
Dim responseText As String
responseText = http.responseText
' Improved JSON parsing
Dim contentPart As String
contentPart = Split(Split(responseText, """content"":""")(1), """")(0)
GetWebData = "AI Response: " & contentPart
Else
GetWebData = "Error connecting to server"
End If
Set http = Nothing
On Error GoTo 0
End Function
Sub StoreSourceData(data As String)
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets("SourceData")
On Error GoTo 0
If ws Is Nothing Then
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "SourceData"
ws.Visible = xlSheetVeryHidden
End If
ws.Range("A1").Value = data
End Sub
Sub ToggleSourceData()
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Sheets("SourceData")
On Error GoTo 0
If Not ws Is Nothing Then
ws.Visible = IIf(ws.Visible = xlSheetVisible, xlSheetVeryHidden, xlSheetVisible)
Else
MsgBox "No source data available", vbInformation
End If
End Sub
Source data hidden in "SourceData" sheet (toggle with Alt+K)
Uses public API for demonstration
To use:
Press Alt+F11 to open VBA editor
Create a module and paste the code
Save as .xlsm and reopen to activate
The button will appear centered in your Excel window. The API call is for demonstration purposes - replace the URL in GetWebData with your actual AI service endpoint.