我有好多本txt小说,想用vb写个程序把txt里的书名和作者信息提取出来保存为excel档案,方便

2025-01-04 14:08:08
推荐回答(3个)
回答1:

1.先将你的txt文件放入特定的文件夹,

2.遍历文件夹内的所有文件,
3.打开文件,提取第一与第二行的数据,

如下VBA代码在Excel里面运行,先修改文件夹名称再运行,

Sub programX()

Application.DisplayAlerts = False :
Application.ScreenUpdating = False : ChengXuWenjianMing = ActiveWorkbook.Name

JiLuBiao = ActiveSheet.Name:
Cells.ClearContents

WenJianJiaMingCheng =
"C:\LiangYouFu\ImportantBackup\" '反斜杠不可省略

WenJianMing = Dir(WenJianJiaMingCheng)

Do While WenJianMing <>
""

WenJianMing = Dir

ChuLiShuJu WenJianJiaMingCheng,
WenJianMing, ChengXuWenjianMing, JiLuBiao

Loop

MsgBox "文件遍历结束,请查看数据!

End Sub

Sub ChuLiShuJu(WenJianJiaMingCheng,
WenJianMing, ChengXuWenjianMing, JiLuBiao)

on error resume next

Open WenJianJiaMingCheng &
WenJianMing for input as #1
line input #1,infox
pox = Application.CountA(Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Range("a:a")) + 1
Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Cells(pox, 1) = infox
line input #1,infox
pox = Application.CountA(Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Range("a:a")) + 1
Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Cells(pox, 1) = infox

close #1

End Sub

回答2:

有什么好处呢?

回答3:

为什么不用xml保存呢?