|
cionysus 发表于 2013-9-6 14:44
很感谢您的帮助!
我还有一个小问题,就是例子中原来命名的区域都是加边框的,但是汇总的表中,这些区域 ... - Sub 提取名称区域()
- Dim ph$, wb As Workbook, sh As Worksheet, arr()
- Dim mypath$, k%, m%, thissh As Worksheet
- On Error Resume Next
- mypath = ThisWorkbook.Path & ""
- ph = Dir(mypath & "*.xls*")
- Do
- Set wb = GetObject(mypath & ph)
- k = 1
- For Each sh In wb.Sheets
- ReDim Preserve arr(1 To 2, 1 To k)
- arr(1, k) = sh.Range("Print_Area")
- arr(2, k) = sh.Name
- If Err.Number = 0 Then k = k + 1 Else Err.Clear
- Next sh
- wb.Close
- For m = 1 To UBound(arr)
- Set thissh = ThisWorkbook.Sheets(Left(ph, Len(ph) - 4) & "-" & arr(2, m))
- If Err.Number <> 0 Then
- ThisWorkbook.Sheets.Add after:=Sheets(Worksheets.Count)
- ActiveSheet.Name = Left(ph, Len(ph) - 4) & "-" & arr(2, m)
- Err.Clear
- Set thissh = ThisWorkbook.Sheets(Left(ph, Len(ph) - 4) & "-" & arr(2, m))
- End If
- With thissh.Range("a1").Resize(UBound(arr(1, m), 1), UBound(arr(1, m), 2))
- .Value = arr(1, m)
- ' .Borders.LineStyle = 1
- .Borders(xlEdgeLeft).LineStyle = 1
- .Borders(xlEdgeTop).LineStyle = 1
- .Borders(xlEdgeBottom).LineStyle = 1
- .Borders(xlEdgeRight).LineStyle = 1
- End With
- Next m
- ph = Dir
- Loop While ph <> "" And ph <> ThisWorkbook.Name
- End Sub
复制代码 |
评分
-
查看全部评分
|