pdf导入表格到excel如何给数据分列
时间:2023-04-29 12:04:32
可执行宏命令。
打开总表1.xlsm文件,执行宏ThisWorkbook.Macro2
代码如下:
Sub Macro2()
Dim fileDir As String '文本文件目录
Dim fileName As String '要打开的文本文件名
Dim serverNo As String
Dim serverDate As String
Dim dataSum As Long '要合并的文本记录数
Dim dataTotalOld As Long '汇总表中未合并时的记录条数
Application.ScreenUpdating = False
fileDir = ActiveWorkbook.Path & "\"
fileName = Dir(fileDir, 7)
Do While fileName <> "" And Right(fileName, 3) = "txt"
'fileName = "1 4-10.txt"
'获取服务器号和日期
serverNo = Left(fileName, InStr(1, fileName, " ") - 1) & "服"
serverDate = Mid(fileName, InStr(1, fileName, " ") + 1)
serverDate = Replace(serverDate, "-", "月")
serverDate = Replace(serverDate, ".txt", "日")
Workbooks.OpenText fileName:= _
ActiveWorkbook.Path + Application.PathSeparator & fileName, Origin:=936, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1)), TrailingMinusNumbers:=True
dataSum = Range("a65535").End(xlUp).Row
Range("A1:D" & dataSum).Select
Range("A1:D" & dataSum).Select
Selection.Copy
'总表1.xlsm为要合并后的启动宏工作表
Workbooks("总表1.xlsm").Activate
dataTotalOld = Range("a65535").End(xlUp).Row + 1
If dataTotalOld = 2 Then dataTotalOld = 1 '第一次使用
Range("C" & dataTotalOld).Select
ActiveSheet.Paste
Range("A" & dataTotalOld) = serverNo
Range("B" & dataTotalOld) = serverDate
Range("A" & dataTotalOld + 1) = serverNo
Range("B" & dataTotalOld + 1) = serverDate
Range("A" & dataTotalOld & ":B" & dataTotalOld + 1).Select
Selection.AutoFill Destination:=Range("A" & dataTotalOld & ":B" & dataTotalOld + dataSum - 1), Type:=xlFillDefault
Workbooks(fileName).Close savechanges:=False
fileName = Dir
Debug.Print fileName
Loop
Application.ScreenUpdating = True
End Sub
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
word在奇偶页怎么设置不同的页眉?
![](https://img.aspxhome.com/file/2023/2/26012_0s.jpg)
excel中利用标签制作三栏表头的方法
![](https://img.aspxhome.com/file/2023/9/40769_0s.jpg)
Excel中两列数据变成一行的操作方法
wps文字菜单栏怎么设置显示
excel怎么画一张糖纸的面积图? excel表格制作糖果纸面积图的技巧
![](https://img.aspxhome.com/file/2023/0/39770_0s.jpg)
Win10预览版15048中Skype率先支持画中画功能
![](https://img.aspxhome.com/file/2023/28/a242479_0s.jpg)
在Word2010中查找和替换字符格式
如何批量把excel数据表格中的合计行删除掉
![](https://img.aspxhome.com/file/2023/4/a154704_0s.jpg)
Windows10如何使用无线同屏功能?
![](https://img.aspxhome.com/file/2023/26/a224976_0s.jpg)
Win10专业版无法弹出U盘怎么回事?
![](https://img.aspxhome.com/file/2023/26/a222577_0s.png)
Pixelmator Pro 教程「122」,如何在 Pixelmator Pro 中应用三角万花筒效果?
![](https://img.aspxhome.com/file/2023/10/a344161_0s.jpeg)
Win10怎样优化系统?Win10优化系统的步骤教程
![](https://img.aspxhome.com/file/2023/25/a218208_0s.png)
Win10控制面板打开是空白的怎么办?
![](https://img.aspxhome.com/file/2023/1/a277711_0s.jpg)
Win10专业版系统groove无法播放音乐提示0x8007007e怎么办?
![](https://img.aspxhome.com/file/2023/5/50175_0s.jpg)
Bapidrv64导致Win10系统开机蓝屏
![](https://img.aspxhome.com/file/2023/4/a305493_0s.jpg)
wps表格如何制作选择男女性别的下拉菜单
如何在Mac电脑上删除APFS分区?
![](https://img.aspxhome.com/file/2023/9/a208659_0s.png)
Win10共享提示输入网络凭据怎么办?
![](https://img.aspxhome.com/file/2023/4/50744_0s.png)
滴滴出行怎么投诉司机?滴滴投诉司机的方法
![](https://img.aspxhome.com/file/2023/7/a331632_0s.jpg)
钉钉如何共享日历?钉钉电脑版日历共享教程
![](https://img.aspxhome.com/file/2023/7/a330063_0s.jpg)