@@ -39,6 +39,12 @@ Sub TextCompletion()
3939
4040 strResponse = .ResponseText
4141
42+ If Mid(strResponse, 6 , 5 ) = "error" Then
43+ MsgBox Prompt:="The server had an error while processing your request. Sorry about that! Please try again"
44+ Exit Sub
45+ End If
46+
47+
4248 Dim intStartPos As Integer
4349 intStartPos = InStr(1 , strResponse, Chr(34 ) & "text" & Chr(34 )) + 12
4450
@@ -50,21 +56,22 @@ Sub TextCompletion()
5056
5157 Dim strOutput As String
5258 strOutput = Mid(strResponse, intStartPos, intLength)
59+
5360
54- Dim strOutputFomatted() As String
55- strOutputFomatted = Split(strOutput, "\n\n" )
56-
57- For Each ArrayResult In strOutputFomatted
58- Selection.MoveDown Unit:=wdParagraph, Count:=1
59- Selection.InsertAfter ArrayResult
60- Selection.Font.Name = "Courier New"
61- Selection.Font.Size = 9
62- Selection.Font.ColorIndex = wdViolet
63- Selection.Paragraphs.Alignment = wdAlignParagraphJustify
64- Next ArrayResult
61+ Dim strOutputFormatted As String , strOutputFormatted1 As String , strOutputFormatted2 As String
62+ strOutputFormatted1 = Replace(strOutput, "\n\n" , vbCrLf)
63+ strOutputFormatted2 = Replace(strOutputFormatted1, "\n" , vbCrLf)
64+ strOutputFormatted = strOutputFormatted2
6565
6666 Selection.Collapse Direction:=wdCollapseEnd
67- Selection.MoveDown Unit:=wdParagraph, Count:=1
67+ Selection.InsertAfter vbCr & strOutputFormatted
68+ Selection.Font.Name = "Courier New"
69+ Selection.Font.Size = 9
70+ Selection.Font.ColorIndex = wdViolet
71+ Selection.Paragraphs.Alignment = wdAlignParagraphJustify
72+ Selection.InsertAfter vbCr
73+ Selection.Collapse Direction:=wdCollapseEnd
74+
6875
6976 End With
7077
0 commit comments