พอดีกำลังปั่น แล้วคิดว่าทำไงจะหาบทความมาปั่นให้ไวได้อย่างไร ลงเอยกับ VBA Excel ข้างล่าง
งดมาม่านะครับ สำหรับคนที่อ่าน code ได้ อาจจะมองออกว่ามันช่วยให้การหาบทความมาทำ layout ได้เร็วขึ้นอย่างไร แชร์ให้ดู และเมนต์กันสนุกๆ แบบได้ความรู้ด้วยนะครับ

Sub GetArticle01()
'
' GetArticle01 Macro
'
Dim FilePath, Content As String
Dim MyObj As Object, MySource As Object, file As Variant
Dim needWord As Integer
Dim xWord, xContent, yContent As String
'Number of word required each lines
needWord = 100
FilePath = "D:\SPIN\asics running shoe\"
MsgBox "Read all files from " & FilePath & "article*.* and then merge to current active cell ?", vbOKCancel
row_number = 0
file = Dir(FilePath)
While (file <> "")
If InStr(file, "article") > 0 Then
Open FilePath & file For Input As #1
Content = ""
Start = False
Do Until EOF(1)
Line Input #1, LineFromFile
'lineItems = Split(LineFromFile, vbCrLf)
If Trim(LineFromFile) <> "" Then
If Not Start Then
ActiveCell.Offset(row_number, 0).Value = LineFromFile
Start = True
Else
Content = Content & " " & LineFromFile
'Split content when words > 200
' If Len(Trim(Content)) - Len(Replace(Content, " ", "")) + 1 > 200 Then
' ActiveCell.Offset(row_number, 1).Value = Content
' row_number = row_number + 1
' Content = ""
' End If
End If
End If
Loop
'Save the last content that have more than 100 words
'If Len(Trim(Content)) - Len(Replace(Content, " ", "")) + 1 > 100 Then
' ActiveCell.Offset(row_number, 1).Value = Content
' row_number = row_number + 1
'End If
Close #1
'Read content and write to excel
xContent = ""
xWord = Split(Content, ".")
For i = 0 To UBound(xWord)
If i < UBound(xWord) Then
xContent = xContent & " " & xWord(i) & "."
Else
xContent = xContent & " " & xWord(i)
End If
If Len(Trim(xContent)) - Len(Replace(xContent, " ", "")) + 1 >= needWord Then
ActiveCell.Offset(row_number, 1).Value = xContent
row_number = row_number + 1
yContent = xContent
xContent = ""
End If
Next i
'Write the last line
If Len(Trim(xContent)) - Len(Replace(xContent, " ", "")) + 1 >= 50 Then
ActiveCell.Offset(row_number, 1).Value = xContent
row_number = row_number + 1
xContent = ""
Else
'If word in last line < 50, append to previous line
xContent = yContent & xContent
ActiveCell.Offset(row_number - 1, 1).Value = xContent
xContent = ""
End If
End If
file = Dir
Wend
End Sub