CSV for Mass Q&A Flashcards (VITAL)

To do mass/fast Page by Page copy and paste using this macro

1
Q

SAVES AS A CSV & ALL Questions & answers in different cells for easier and faster copying and pasting //

USED FOR WINDOWS

A

Sub FormatFlashcardsAndSaveCSV()
Dim doc As Document
Dim para As Paragraph
Dim text As String
Dim formattedText As String
Dim csvContent As String
Dim filePath As String
Dim fileNum As Integer
Dim fd As FileDialog
Dim isFirst As Boolean

Set doc = ActiveDocument

' Initialize CSV content
csvContent = "Question,Answer" & vbCrLf
isFirst = True

For Each para In doc.Paragraphs
    text = para.Range.text
    ' Remove trailing paragraph mark
    If Right(text, 1) = vbCr Then text = Left(text, Len(text) - 1)
    ' Check if the paragraph contains "Q:" and "A:"
    If InStr(text, "Q: ") > 0 And InStr(text, "A: ") > 0 Then
        ' Extract question and answer
        Dim question As String
        Dim answer As String
        question = Mid(text, InStr(text, "Q: ") + 3, InStr(text, "A: ") - (InStr(text, "Q: ") + 3))
        answer = Mid(text, InStr(text, "A: ") + 3)
        ' Format the text
        formattedText = """" & Replace(question, """", """""") & """,""" & Replace(answer, """", """""") & """"
        ' Append to CSV content
        csvContent = csvContent & formattedText & vbCrLf
        isFirst = False
    End If
Next para

' Remove the last newline if no flashcards were processed
If isFirst Then
    MsgBox "No flashcards found to save."
    Exit Sub
End If

' Show Save As dialog to choose the file path
Set fd = Application.FileDialog(msoFileDialogSaveAs)
fd.Title = "Save CSV File"

If fd.Show = -1 Then
    filePath = fd.SelectedItems(1)
    ' Ensure the file path has a .csv extension
    If Not filePath Like "*.csv" Then filePath = filePath & ".csv"
    ' Open the file for output
    fileNum = FreeFile
    Open filePath For Output As #fileNum
    ' Write the CSV content
    Print #fileNum, csvContent
    ' Close the file
    Close #fileNum

    MsgBox "Flashcards saved as CSV successfully!"
Else
    MsgBox "Save operation canceled."
End If End Sub
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

MACRO FOR MACBOOK ————>

A

Sub FormatFlashcardsAndSaveCSV()
Dim doc As Document
Dim para As Paragraph
Dim text As String
Dim formattedText As String
Dim csvContent As String
Dim filePath As String
Dim fileNum As Integer
Dim isFirst As Boolean

On Error GoTo ErrorHandler

Set doc = ActiveDocument

' Initialize CSV content
csvContent = "Question,Answer" & vbLf
isFirst = True

For Each para In doc.Paragraphs
    text = para.Range.text
    ' Remove trailing paragraph mark
    If Right(text, 1) = vbLf Or Right(text, 1) = vbCr Then text = Left(text, Len(text) - 1)
    ' Check if the paragraph contains "Q:" and "A:"
    If InStr(text, "Q: ") > 0 And InStr(text, "A: ") > 0 Then
        ' Extract question and answer
        Dim question As String
        Dim answer As String
        question = Mid(text, InStr(text, "Q: ") + 3, InStr(text, "A: ") - (InStr(text, "Q: ") + 3))
        answer = Mid(text, InStr(text, "A: ") + 3)
        ' Format the text
        formattedText = """" & Replace(question, """", """""") & """,""" & Replace(answer, """", """""") & """"
        ' Append to CSV content
        csvContent = csvContent & formattedText & vbLf
        isFirst = False
    End If
Next para

' Remove the last newline if no flashcards were processed
If isFirst Then
    MsgBox "No flashcards found to save."
    Exit Sub
End If

' Ask the user to input the file path
filePath = InputBox("Enter the full path and name of the CSV file:", "Save CSV File", Environ("HOME") & "/Documents/Flashcards.csv")

' Exit if no path was provided
If filePath = "" Then
    MsgBox "Save operation canceled."
    Exit Sub
End If

' Ensure the file path has a .csv extension
If Not filePath Like "*.csv" Then filePath = filePath & ".csv"

' Open the file for output
fileNum = FreeFile
Open filePath For Output As #fileNum
' Write the CSV content
Print #fileNum, csvContent
' Close the file
Close #fileNum

MsgBox "Flashcards saved as CSV successfully!"
Exit Sub

ErrorHandler:
MsgBox “Error “ & Err.Number & “: “ & Err.Description, vbCritical, “Error”
Resume Next
End Sub

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

TROUBLESHOOT/MACRO TO WORK

(1)THERE CAN NOT BE ANY GAPS for the Flashcards or CSV will not be generated b/ween Q:& A:

A

CORRECT
Q: What does the BASE CLOSURE/PHASEDOWN FLAG indicate?A: It identifies items in the base closure or phasedown program. A zero means the base closure flag is off, and a one means
the base closure flag is in effect.
_____________________________________________

WRONG
Q: What does the BASE CLOSURE/PHASEDOWN FLAG indicate? A: It identifies items in the base closure or phasedown program. A zero means the base closure flag is off, and a one means
the base closure flag is in effect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

TROUBLESHOOT/MACRO TO WORK

(2) formatting of the text in your document. The macro is looking for “Q: “ and “A: “ with a space after the colon

A

WRONG= FLASHCARD 1 Q:What is the purpose of creating workspaces and living quarters during operations?A:To ensure operational effectiveness and readiness.
_______________________________________
CORRECT= FLASHCARD 1 Q: What is the purpose of creating workspaces and living quarters during operations?A: To ensure operational effectiveness and readiness

How well did you know this?
1
Not at all
2
3
4
5
Perfectly