5,139
社区成员
发帖
与我相关
我的任务
分享
Sub mysub()
Dim ShApp As Object, mysheet As Object
Dim TF As Boolean, i As Integer, j As Integer
Dim aTable As Object, n As Integer
Dim mypath, mypathtxt As String
On Error Resume Next
n = 0
mypath = ThisWorkbook.Path
mypathtxt = mypath & "\txt"
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "请选定要处理的excel文档"
.Filters.Add "excel文档", "*.xlsx"
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
Set ShApp = GetObject(, "Excel.Application")
If Err <> 0 Then
TF = True
Set ShApp = CreateObject("Excel.Application")
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 1 To .SelectedItems.Count
Set mysheet = ShApp.Workbooks.Open(.SelectedItems(i))
With mysheet.Sheets(1)
j = .[A65535].End(xlUp).Row
.Range(.Cells(1, 3), .Cells(j, 3)).Value = 1500
.Range(.Cells(1, 1), .Cells(j, 1)).Value = .Range(.Cells(1, 3), .Cells(j, 3)).Value * 3
Sheets(1).Copy
ActiveWorkbook.SaveAs Filename:=mypathtxt & "\" & i & ".txt", FileFormat:=xlText
ActiveWorkbook.Close
End With
n = n + 1
mysheet.Close True
Next i
End With
If TF = True Then ShApp.Quit
Set ShApp = Nothing
MsgBox "处理完毕,共处理了" & n & "个excel文档。"
Application.ScreenUpdating = True
End Sub