|
Option Explicit
Sub TEST()
Dim ar, i&, strFileName$, strPath$, iRow&
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "保存到指定工作表中.xlsm"
If Dir(strFileName) = "" Then MsgBox "指定的文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
ar = [A1].CurrentRegion.Value
With Workbooks.Open(strFileName)
If isWksExists1("类别" & ar(2, 1)) Then
With .Sheets("类别" & ar(2, 1))
iRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Cells(iRow, 1) = ar(2, 1)
.Cells(iRow, 2) = ar(2, 2)
End With
Else
With .Sheets.Add(after:=.Sheets(.Sheets.Count))
.Name = "类别" & ar(2, 1)
.[A1].Resize(UBound(ar), UBound(ar, 2)) = ar
End With
End If
.Close True
End With
Application.ScreenUpdating = True
Beep
End Sub
Public Function isWksExists1(wksName As String) As Boolean
On Error Resume Next
isWksExists1 = Sheets(wksName).Name = wksName
End Function
|
评分
-
1
查看全部评分
-
|