我有好多本txt小说,想用vb写个程序把txt里的书名和作者信息提取出来保存为excel档案,方便
我有好多本txt小说,想用vb写个程序把txt里的书名和作者信息提取出来保存为excel档案,方便查阅(txt文件内第一行是书名,第二行是作者名字),求源码?谢谢...
我有好多本txt小说,想用vb写个程序把txt里的书名和作者信息提取出来保存为excel档案,方便查阅(txt文件内第一行是书名,第二行是作者名字),求源码?谢谢
展开
3个回答
展开全部
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.打开文件,提取第一与第二行的数据,
如下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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询