赞
踩
针对 Office 2003 的支持已终止
Microsoft 已于 2014 年 4 月 8 日终止了针对 Office 2003 的支持。该更改已影响到您的软件更新和安全选项。 了解这一措施对于您的含义以及如何继续保持受保护状态。
-
- Sub CopySheetTest()
- Dim iTemp As Integer
- Dim oBook As Workbook
- Dim iCounter As Integer
-
- ' Create a new blank workbook:
- iTemp = Application.SheetsInNewWorkbook
- Application.SheetsInNewWorkbook = 1
- Set oBook = Application.Workbooks.Add
- Application.SheetsInNewWorkbook = iTemp
-
- ' Add a defined name to the workbook
- ' that RefersTo a range:
- oBook.Names.Add Name:="tempRange", _
- RefersTo:="=Sheet1!$A$1"
-
- ' Save the workbook:
- oBook.SaveAs "c:\test2.xls"
-
- ' Copy the sheet in a loop. Eventually,
- ' you get error 1004: Copy Method of
- ' Worksheet class failed.
- For iCounter = 1 To 275
- oBook.Worksheets(1).Copy After:=oBook.Worksheets(1)
- Next
- End Sub
-
- Sub CopySheetTest()
- Dim iTemp As Integer
- Dim oBook As Workbook
- Dim iCounter As Integer
-
- ' Create a new blank workbook:
- iTemp = Application.SheetsInNewWorkbook
- Application.SheetsInNewWorkbook = 1
- Set oBook = Application.Workbooks.Add
- Application.SheetsInNewWorkbook = iTemp
-
- ' Add a defined name to the workbook
- ' that RefersTo a range:
- oBook.Names.Add Name:="tempRange", _
- RefersTo:="=Sheet1!$A$1"
-
- ' Save the workbook:
- oBook.SaveAs "c:\test2.xls"
-
- ' Copy the sheet in a loop. Eventually,
- ' you get error 1004: Copy Method of
- ' Worksheet class failed.
- For iCounter = 1 To 275
- oBook.Worksheets(1).Copy After:=oBook.Worksheets(1)
- 'Uncomment this code for the workaround:
- 'Save, close, and reopen after every 100 iterations:
- If iCounter Mod 100 = 0 Then
- oBook.Close SaveChanges:=True
- Set oBook = Nothing
- Set oBook = Application.Workbooks.Open("c:\test2.xls")
- Set oBook = Application.Workbooks.Open("c:\test2.xlsx")
- End If
- Next
- End Sub
文章 ID:210684 - 上次审阅时间:02/26/2007 12:42:00 - 修订版本: 6.2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。