Home > Software engineering >  EXCEL VBA to merge the current directory all the worksheets for all workbook, prompt invalid or unqu
EXCEL VBA to merge the current directory all the worksheets for all workbook, prompt invalid or unqu

Time:11-19

Sub all workbook merging the current directory of all the work table ()
Dim mypath, myname, awbname
Dim wb As Workbook, WBN As String
Dim g As Long
Dim num As Long
Dim box As String
Application. ScreenUpdating=False
Myname=ActiveWorkbook. Path
Myname=Dir (mypath & amp; "" "*. XLS")
Awbname=ActiveWorkbook. Name
Num=0
The Do While myname & lt;> "
"If myname & lt;> Awbname Then
The Set wb=Workbook. Open (mypath & amp; "" & amp; Myname)
Num=num + 1
With Workbooks (1). ActiveSheet. Cells (the Range (" A65536 "). The End (xlUp). Row + 1, 1)=Left (myname. Len (myname) - (4)
For g=1 To wb. Sheets. Count
K=k + 1
If k=1 Then
Wb. Sheets (g). 2 Range. Copy) Cells () Range (" B "& amp; Row. The Count). End (xlUp).
Row + 1, 1)The Else
Wb. Sheets (g). 2 Range. The Offset (1, 0) (Copy) Cells () Range (" B "& amp; Rows. Count). End (xlUp).
Row + 1, 1)End the If
Next
WBN=WBN & amp; CRH (13) & amp; Wbname
Wb. Close False
End With
End the If
Myname=Dir
Loop
Range (" A1 "). Select
Application. ScreenUpdating=True
MsgBox "merged together" & amp; Num & amp; "A job under the thin all work table, as follows:" & amp; CRH (13) & amp; WBN vbInformation, "tip"
End Sub
  •  Tags:  
  • VBA
  • Related