Skip to content

Commit 9d21bf0

Browse files
committed
Minor Change
Added valid file check to the function that retrieves the API key from an external file
1 parent d006c78 commit 9d21bf0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

OpenAIFrameworkDemo.xlsm

511 Bytes
Binary file not shown.

clsOpenAI.cls

+8-2
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,20 @@ Public Sub ClearSettings()
454454
End Sub
455455

456456

457-
Public Function GetReadAPIKeyFromFolder(ByVal strfolderPath As String) As String
457+
Public Function GetReadAPIKeyFromFolder(ByVal strfolderPath As String, Optional ByVal strDefaultTextFileName As String = "apikey") As String
458458
'Purpose: Allows retrieval of an API KEY saved in an external file (possibly stored on a drive only the current user can access)
459459

460460
Dim intFileNumber As Integer
461461
Dim strAPIKey As String
462462
Dim strFilePath As String
463463

464-
strFilePath = strfolderPath & "\apikey.txt" ' Construct the full file path
464+
strFilePath = strfolderPath & "\" & strDefaultTextFileName & ".txt" ' Construct the full file path
465+
466+
'check file exists
467+
If Dir(strFilePath) = "" Then
468+
GetReadAPIKeyFromFolder = Empty
469+
Exit Function
470+
End If
465471

466472
intFileNumber = FreeFile ' Get the first available file number
467473

0 commit comments

Comments
 (0)