Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Import an Entire Worksheet from an Excel Workbook


View products that this article applies to.

Summary

This article shows you how to use Visual Basic for Applications to import an entire worksheet from a Microsoft Excel workbook without specifying a range.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To import an entire worksheet, refer to the worksheet without a named range, but include an exclamation point (!). For example, the following sample code imports Sheet5 from a workbook named T.xls located on drive C.
Function ImportXL()
   DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
     "TestTable", "C:\T.XLS", True, "Sheet5!"
End Function
				
If you do not specify a value for the last argument, Microsoft Access imports the first worksheet that it finds in the workbook. If you specify a range, that range is imported from the first worksheet in the workbook. To specify a range from a specific worksheet, use the following syntax, which refers to cells A1 through G50:
Sheet5!A1:G50
NOTE: If the sheet name contains a special character, you must enclose it in apostrophes (' '); otherwise, you receive a run-time error. For example, if the sheet has the name Test#Sheet, the last argument would be "'Test#Sheet!'".

↑ Back to the top


Keywords: KB210379, kbinterop, kbhowto

↑ Back to the top

Article Info
Article ID : 210379
Revision : 5
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 295