3 Ways to Integrate DeepSeek in Excel

Deepanshu Bhalla Add Comment

In this post, we will talk about various ways to integrate DeepSeek into MS Excel. DeepSeek has a public API which makes it easy to use DeepSeek in MS Excel.

Using DeepSeek in Excel

How to Get DeepSeek API

Step 1 : Get API Key
  1. You can sign up for an account on DeepSeek's platform by visiting platform.deepseek.com and then create an account using your email address.
  2. Click the Top up button on the left side of the menu and then select the amount you wish to add. Next choose a payment method and enter your details to complete the payment.

    If you get an error while using debit/credit card as a payment method that your country is not supported, you can use Paypal and then choose Pay with Credit or Debit Card option. You don't need paypal account for the same.
  3. Click the API keys button on the left side of the menu and then click on Create a new API key button. The API key will look like the following.
sk-xxxxxxxxxxxxx
3 Methods to Use DeepSeek in Excel
  1. Excel Plugin for DeepSeek
  2. Excel Macro for DeepSeek
  3. Excel Function for DeepSeek

Method 1 : Excel Plugin for DeepSeek

You can download the Excel plugin for DeepSeek by clicking on Download button. In Excel, a plugin is referred to as an add-in. Don't get confused. Plugin and add-in are essentially the same in MS Excel.


How to install add-in

When you download add-in or macro file from internet, Microsoft blocks them from running and shows the source of this file is untrusted. You need to follow the steps below to make it working.

  1. Go to the folder where the downloaded add-in file is located.
  2. Right-click the file and choose Properties from the menu.
  3. At the bottom of the General Tab, select the Unblock checkbox under security option and then click OK.

Refer the following steps to install DeepSeek add-in in MS Excel.

  1. Open Excel and click on the File tab in the ribbon.
  2. Click on Options and then select Add-ins from the left-hand menu.
  3. In the Manage drop-down menu at the bottom of the screen, select Excel Add-ins and click on the Go button.
  4. Click on the Browse button and locate the add-in file that you downloaded.
  5. Select the add-in file and click on the OK button.
  6. You should see the name of the add-in file in the Add-Ins dialog box. Check the box next to the add-in name to activate it.
  7. Once you are done with the above steps, a new tab called DeepSeek should be visible in your Excel workbook.
How to use DeepSeek's Excel add-in

Follow the steps below to use DeepSeek add-in for MS Excel.

  1. Open a new or existing MS Excel Workbook
  2. Enter text you want to ask DeepSeek in any cell
  3. Click on DeepSeek Tab > DeepSeek Assistant.
  4. Enter your API Key and select Model Type.
  5. Select the cell in which you entered text in step 2.
  6. Output will be generated and will appear within a few seconds.
  7. When you want DeepSeek to run on multiple cells, you can use the DeepSeek function. See the details in the next section.
Features of DeepSeek's Excel Add-in

This add-in can generate both text and images and has the following features:

  1. Text Generation
  2. Multi-turn Conversations (Chat)
  3. Fill Missing Data
  4. Extract Key Information
  5. Translate Text
  6. Learn Excel Formulas with DeepSeek
  7. Data Insights
  8. Building Question and Answering System

Text Generation

The DeepSeek function generates text output based on a search query using DeepSeek.

Syntax
DeepSeek(text, [word_count])
Arguments
  • text : Text you want to search
  • word_count : Optional. Specify the maximum number of words for the output generated by DeepSeek.
Example
=DeepSeek("First President of US")

If you want to limit the response from DeepSeek to a maximum of 2 words, specify '2' as the second argument of the function. For example, =DeepSeek("First President of US", 2).

Handling Non-English Text

Sometimes non-english letters do not get displayed correctly in the response coming from DeepSeek API due to UTF-8 encoding issue. To fix this issue you can apply the CleanMsg function to the output of DeepSeek or any other function. Please refer to the example below.

=CleanMsg(DeepSeek("Write a post about 'Good morning' in Spanish"))

Chat Conversations

By default when DeepSeek API answers your question, it does not remember your previous conversations. It is important for AI to remember previous conversations in order to better understand you so that it can improve its responses each time.

The function DeepSeek_Chat is used to activate multi-turn conversations.

Syntax
DeepSeek_Chat(text, [reset])
Arguments
  • text : Text you want to search
  • reset : Optional. Set it to TRUE to start/reset chat session.
Example
=DeepSeek_Chat("2+2")
=DeepSeek_Chat("square of it")
Output

"**Solution:**

To find the square of the sum \(2 + 2\), follow these steps:

1. **First, calculate the sum:**
   \[
   2 + 2 = 4
   \]

2. **Now, square the result:**
   \[
   4^2 = 4 \times 4 = 16
   \]

**Final Answer:**
\[
\boxed{16}
\]"
It is recommended to set the second argument of the function reset as TRUE when you do not need DeepSeek to recall your prior conversations.

Data Insights

Please follow the steps below to generate data insights or find hidden patterns in your data with this plugin.

  1. Click on the Generate Insights button in the DeepSeek tab on the ribbon in Excel.
  2. In the message dialog box, select cells containing data (including the header) and then click "OK". For example, A1:D101.
  3. Wait for the insights generated from DeepSeek API.
  4. In the message dialog box, select a cell where the output will be saved. For example, F2.
  5. Select "yes" or "no" if you want the output to be populated in multiple rows or a single row.

The function DeepSeek_Insights is used to generate insights from data.

Syntax
DeepSeek_Insights(rng_data, [prompt])
Arguments
  • rng_data : Specify cells containing data (including the header).
  • prompt : Optional. Provide specific information you want about the data.
Example
=DeepSeek_Insights(A1:D101,"Generate Top 5 Insights")

Translate with DeepSeek

The function DeepSeek_Translator is used to translate text. Just enter the text you want to translate and the language name, it will give you translations.

Syntax
DeepSeek_Translator(text, language)
Arguments
  • text : Specify the cell that contains text you want to translate.
  • language : Name of language. E.g. Spanish, French etc.
Example
=DeepSeek_Translator("Hello, How are you?", "german")

Extract Key Information

The DeepSeek_Extractor function can be used to fetch key information such as name, location etc from the text.

Syntax
DeepSeek_Extractor(prompt, keyword)
Arguments
  • prompt : Specify the cell that contains text from which you want to extract key data.
  • keyword : Keyword can be name, place, organization etc.
Example

Suppose you have text "Dave went to New York for studies" in cell B2. You want to extract name and location from the text. Enter the following formula in cells C2 and D2.

=DeepSeek_Extractor(B2,"name")
=DeepSeek_Extractor(B2,"location")

Fill Missing Data

The DeepSeek_FillData function can be used for a variety of purposes. See some of the real-world use cases below.

  1. Sentiment Analysis You can label positive/negative/neutral sentiments on customer feedback data. You just need to provide a few labels in first argument of the function.
  2. Industry/Sector Classification You have companies name and wish to find out their industries/sectors.
  3. Text Patterns Extraction You have text data which contains both character and numeric values. By using this function, you can extract numeric values from the text.
Syntax
DeepSeek_FillData(rng_existingdata, rng_fill)
Arguments
  • rng_existingdata : Range of training data
  • rng_fill : Specify the cell that needs to be filled in.
Example
Fill Missing Data in Excel using DeepSeek

Building Question and Answering System

The DeepSeek_QnA function is used to build a question and answering system. You input a paragraph or a text document along with your question and it helps you find the relevant answer within that text. It can be useful for tasks like quickly extracting information from large text without the need to manually search through the text.

Syntax
DeepSeek_QnA(query, passage)
Arguments
  • query : Specify the cell containing a question.
  • passage : Specify the cell containing a large text.
Example
=DeepSeek_QnA(B6, B3)

You can also specify multiple cells for a passage like in the example below.

=DeepSeek_QnA(A2, A3:A10)

Learn Excel Formulas with DeepSeek

The DeepSeek_Explain function helps you explain any Excel formula.

Syntax
DeepSeek_Explain(cell_formula, [detail])
Arguments
  • cell_formula : Cell that contains an Excel formula that you want DeepSeek to explain to you.
  • detail : Optional. Default value is TRUE. Set FALSE if you want less verbose resonse.
Example

Let's say you have a formula in cell B2: =VLOOKUP(B2,$B$2:$D$5,2,FALSE). If you enter this formula =DeepSeek_Explain(B2) in cell C2, it will provide an explanation for the VLOOKUP function.

How to Handle Large Number of Prompts

Suppose you have more than 100 prompts distributed across 100 cells in an Excel sheet and you want to get answers for each prompt using DeepSeek. If you attempt to do this all at once by dragging the DeepSeek function to 100 rows, it may cause Excel to slow down or show errors because it can't handle so many requests together.

To fix this issue, you can ask one question at a time instead of sending all the questions to DeepSeek at once. Then move on to the next question and repeat the process. In the code below, we assumed prompts starting from cell B3.

Sub DeepSeekLoop()

    Dim ws As Worksheet
    Dim promptColumn As String
    Dim promptRng As String
    Dim startRow As Long
    Dim cell As Range
    Dim result As Variant
    Dim lastRow As Long

    ' Set the active sheet as the working sheet
    Set ws = ActiveSheet

    ' Set the column having prompts. For e.g., prompts starting from cell B3
    promptColumn = "B"
    startRow = 3

    ' Find the last row in column
    lastRow = ws.Cells(ws.Rows.Count, promptColumn).End(xlUp).Row

    ' Loop through cells to the last row
    promptRng = promptColumn & startRow & ":" & promptColumn & lastRow
    For Each cell In ws.Range(promptRng)

        ' Check if the cell is not empty
        If Not IsEmpty(cell.Value) Then
            
            ' Handle errors and continue with the next iteration
            On Error Resume Next
            
            ' Call the DeepSeek function with the cell value
            result = Application.Run("DeepSeek", cell.Value)
            
            ' If there was an error, skip to the next iteration
            If Err.Number <> 0 Then
                Err.Clear
                On Error GoTo 0
                GoTo NextCell
            End If
            
            ' Reset error handling
            On Error GoTo 0
            
            ' Paste the value back into the adjacent column
            cell.Offset(0, 1).Value = result
        
        End If

NextCell:
    Next cell

End Sub
Run the macro by pressing Alt+F8, selecting the macro DeepSeekLoop and clicking the Run button.

If you are still getting errors, you can add a wait time between each iteration. You can use the Application.Wait Now + TimeValue("00:00:01") code immediately after NextCell: in the code above to wait for one second before the next iteration.

If you also want to use CleanMsg function, use this Application.Run("CleanMsg", Application.Run("DeepSeek", cell.Value))

Method 2 : Excel Macro for DeepSeek

This method is simply an alternative to using an add-in. It contains VBA code that fetches responses from DeepSeek using the API and places them into Excel. It also cleans the responses from DeepSeek and puts them in a structured format to maintain formatting.

This macro only works on Windows OS. If you want to integrate DeepSeek into MS Excel on Mac OS, please use the add-in shown in the previous section of this article.
Sub DeepSeek()
  
  Dim request As Object
  Dim response As String
  Dim text, API, api_key, DisplayText, error_result As String
  Dim status_code As Long
  Dim cellr As Range
  Dim prompt, rng As Range
  
  'API Info
  API = "https://api.deepseek.com/chat/completions"
  api_key = "sk-xxxxxxxxxxxxxxxxxx"

  If api_key = "" Then
        MsgBox "Error: API key is blank!"
        Exit Sub
    End If
    
  Set prompt = Range("B3")
  Set cellr = prompt.Offset(1, 0)
  Set rng = Range(prompt.Offset(1, 0), prompt.Offset(2000, 0))
  rng.Clear
    
  'Input Text
    If prompt.Value = "" Then
        MsgBox "Error: Cell " & prompt.Address(RowAbsolute:=False, ColumnAbsolute:=False) & " is blank!"
        Exit Sub
    End If

  text = Replace(prompt.Value, Chr(34), Chr(39))
  text = Replace(text, vbLf, " ")

  'Create an HTTP request object
  Set request = CreateObject("MSXML2.XMLHTTP")
  With request
     .Open "POST", API, False
     .setRequestHeader "Content-Type", "application/json"
     .setRequestHeader "Authorization", "Bearer " & api_key
     .send "{""model"": ""deepseek-chat"",  ""messages"": [{""content"":""" & text & """,""role"":""user""}]," _
          & """temperature"": 1}"
   status_code = .Status
   response = .responseText
  End With

  'Extract content
  If status_code = 200 Then
    DisplayText = ExtractContent(response)
  Else
    DisplayText = ExtractError(response)
  End If
    
  'Put response
  cellr.Value = DisplayText
  
  'Split to multiple rows
  Call SplitTextToMultipleRows(cellr)
  rng.WrapText = True
    
  'Clean up the object
  Set request = Nothing

End Sub

Sub SplitTextToMultipleRows(cell As Range)
    Dim splitArr() As String
    Dim delimiter As String
    delimiter = "\n"
    
    splitArr = Split(cell.Value, delimiter)
    For i = LBound(splitArr) To UBound(splitArr)
        x = splitArr(i)
        If Left(Trim(x), 1) = "=" Then
            x = "'" & x
        End If
        cell.Offset(i, 0).Value = Replace(x, "\""", Chr(34))
    Next i
    
End Sub

Function ExtractContent(jsonString As String) As String
    Dim startPos As Long
    Dim endPos As Long
    Dim Content As String

    ' Find "choices" array
    startPos = InStr(jsonString, """choices""")
    If startPos = 0 Then
        ExtractContent = "Error: 'choices' not found"
        Exit Function
    End If

    ' Find "message" within the first choice
    startPos = InStr(startPos, jsonString, """message""")
    If startPos = 0 Then
        ExtractContent = "Error: 'message' not found"
        Exit Function
    End If

    ' Find "content" key inside the first "message"
    startPos = InStr(startPos, jsonString, """content""")
    If startPos = 0 Then
        ExtractContent = "Error: 'content' not found"
        Exit Function
    End If

    ' Move startPos to start of content text
    startPos = startPos + Len("""content"":""")

    ' Find the closing quote for the content text
    endPos = InStr(startPos, jsonString, """")
    If endPos = 0 Then
        ExtractContent = "Error: End of 'content' not found"
        Exit Function
    End If

    ' Extract the content
    Content = Mid(jsonString, startPos, endPos - startPos)

    ' Replace escaped quotes
    Content = Replace(Content, "\""", Chr(34))

    ' Fix for Excel formulas
    If Left(Trim(Content), 1) = "=" Then
        Content = "'" & Content
    End If

    ' Remove unnecessary line breaks
    Content = Replace(Content, vbCrLf, "")
    Content = Replace(Content, vbLf, "")
    Content = Replace(Content, vbCr, "")

    ExtractContent = Content
End Function


Function ExtractError(jsonString As String) As String
    Dim startPos As Long
    Dim endPos As Long
        startPos = InStr(jsonString, """message"": """) + Len("""message"": """)
        endPos = InStr(startPos, jsonString, """")
        If startPos > Len("""message"": """) And endPos > startPos Then
            ExtractError = Mid(jsonString, startPos, endPos - startPos)
        Else
            startPos = InStr(jsonString, """code"": """) + Len("""code"": """)
            endPos = InStr(startPos, jsonString, """")
            If startPos > Len("""code"": """) And endPos > startPos Then
              ExtractError = Mid(jsonString, startPos, endPos - startPos)
            Else
              ExtractError = "Unknown error"
            End If
        End If
End Function
Instructions to Use Macro
  1. Press Alt+F11 to open the VBA editor.
  2. Click Insert > Module to create a new module.
  3. In the module, copy and paste the VBA code mentioned above.
  4. You need to enter your API key in the code above in the variable api_key. This is the same secret key which we obtained in the previous step.
  5. Enter your question (prompt) in cell B3 and then follow the steps below.
  6. Specify deepseek-reasoner in the model argument to use DeepSeek-R1 model.
  7. Close the VBA editor and then run the macro by pressing Alt+F8 or by going to the Developer tab > Macros and select the macro DeepSeek and hit Run button.

Method 3 : Excel Function for DeepSeek

You can also run DeepSeek as an excel function. The benefit of running it as function is that you can paste it down on multiple cells.

Function DeepSeekAI(text As String, Optional word_count As Long = 0) As String
  
  Dim request As Object
  Dim response As String
  Dim API, api_key, DisplayText, error_result As String
  Dim startPos, endPos, status_code As Long
  Dim rng As Range
  
  'API Info
  API = "https://api.deepseek.com/chat/completions"
  api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxxx"
  
  'Input Text
   If word_count > 0 Then
    text = text & ". Provide response in maximum " & word_count & " words"
   End If
  
  text = Replace(text, Chr(34), Chr(39))
  text = Replace(text, vbLf, " ")
          
  'Send request to API
  Set request = CreateObject("MSXML2.XMLHTTP")
  With request
     .Open "POST", API, False
     .setRequestHeader "Content-Type", "application/json"
     .setRequestHeader "Authorization", "Bearer " & api_key
     .send "{""model"": ""deepseek-chat"",  ""messages"": [{""content"":""" & text & """,""role"":""user""}]," _
          & """temperature"": 1}"
   status_code = .Status
   response = .responseText
  End With
  
  'Parse response from API
  If status_code = 200 Then
    DisplayText = ExtractContent(response)
  Else
    DisplayText = ExtractError(response)
  End If
  
    If word_count > 0 And Right(DisplayText, 1) = "." Then
        DisplayText = Left(DisplayText, Len(DisplayText) - 1)
    Else
        DisplayText = DisplayText
    End If
  
  'Return result
  DeepSeekAI = DisplayText

End Function

Function ExtractContent(jsonString As String) As String
    Dim startPos As Long
    Dim endPos As Long
    Dim Content As String

    ' Find "choices" array
    startPos = InStr(jsonString, """choices""")
    If startPos = 0 Then
        ExtractContent = "Error: 'choices' not found"
        Exit Function
    End If

    ' Find "message" within the first choice
    startPos = InStr(startPos, jsonString, """message""")
    If startPos = 0 Then
        ExtractContent = "Error: 'message' not found"
        Exit Function
    End If

    ' Find "content" key inside the first "message"
    startPos = InStr(startPos, jsonString, """content""")
    If startPos = 0 Then
        ExtractContent = "Error: 'content' not found"
        Exit Function
    End If

    ' Move startPos to start of content text
    startPos = startPos + Len("""content"":""")

    ' Find the closing quote for the content text
    endPos = InStr(startPos, jsonString, """")
    If endPos = 0 Then
        ExtractContent = "Error: End of 'content' not found"
        Exit Function
    End If

    ' Extract the content
    Content = Mid(jsonString, startPos, endPos - startPos)

    ' Replace escaped quotes
    Content = Replace(Content, "\""", Chr(34))

    ' Fix for Excel formulas
    If Left(Trim(Content), 1) = "=" Then
        Content = "'" & Content
    End If

    ' Remove unnecessary line breaks
    Content = Replace(Content, vbCrLf, "")
    Content = Replace(Content, vbLf, "")
    Content = Replace(Content, vbCr, "")

    ExtractContent = Content
End Function


Function ExtractError(jsonString As String) As String
    Dim startPos As Long
    Dim endPos As Long
        startPos = InStr(jsonString, """message"": """) + Len("""message"": """)
        endPos = InStr(startPos, jsonString, """")
        If startPos > Len("""message"": """) And endPos > startPos Then
            ExtractError = Mid(jsonString, startPos, endPos - startPos)
        Else
            startPos = InStr(jsonString, """code"": """) + Len("""code"": """)
            endPos = InStr(startPos, jsonString, """")
            If startPos > Len("""code"": """) And endPos > startPos Then
              ExtractError = Mid(jsonString, startPos, endPos - startPos)
            Else
              ExtractError = "Unknown error"
            End If
        End If
End Function
Make sure you enter your API key highlighted in bold above.

Follow the steps 1 to 4 in the previous section "How to use VBA Code". Once you are through with these 4 steps, type =DeepSeek(B3) in any cell. Here B3 refers to the cell wherein your prompt (question) is placed.

How to Use DeepSeek to Write Excel Formulas

You can use the above add-in or macro and ask DeepSeek to act like an excel tutor and help you in writing Excel formulas.

=DeepSeek("Excel formula for 'Pass' if a value in cell F5 is less than 70, else 'Fail'")

How to Use DeepSeek to Write VBA Code

It also works well for advanced excel concepts like macros. It can write VBA code for you. Writing VBA code has never been easier before with DeepSeek.

=DeepSeek("Write VBA code to apply filter on sheet1 and paste filtered rows to sheet2")

How to Fine Tune DeepSeek Response

You would find temperature parameter in the VBA code. It lies between 0 and 2. Use 0 value for coding or math related problems. Use default value of 1 for data analysis and 1.5 for creative writing.

Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "3 Ways to Integrate DeepSeek in Excel"
Next → ← Prev