P. 1
81959924 AutoCAD VBA Programming Tools and Techniques

81959924 AutoCAD VBA Programming Tools and Techniques

|Views: 280|Likes:
Published by xuanhuynh

More info:

Published by: xuanhuynh on Nov 02, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/12/2013

pdf

text

original

Page 175

This way we can control the exit situation and issue a proper error message that makes sense to the user.

By including the empty string as the first parameter to the getObject( ) function, we are instructing VBA to run Excel if
it is not already running in the computer. Leaving the first parameter blank will cause an error if an instance of Excel
does not already exist in the machine.

Another way to access the workbook object is through the create-Object( ) function. This function behaves just like
getObject( ) except that it will start the application. If your application knows it will be starting Excel when it is going to
run, then the createObject( ) function is a better choice.

The next step is to open the workbook using the Open method of the Workbooks object in Excel. You'll supply the
complete file name, with extension, to the Open function. No directory was specified in the example routine. The file is
assumed to be in the Excel or system search path. If it's not in the search path, you'll need to provide a complete path
name. The extension XLS will not be appended automatically, which means that your application can use alternative
extensions as a minimal form of data security. The result of a successful open call is a workbook object.

Workbooks contain worksheets, so the next level into the object tree takes our application to the specific sheet we wish
to have available. The example program selects ''Sheet1", the default sheet name in a new workbook. The worksheet
object is then assigned to the variable excelSheet.

The result of running this function is that the workbook and worksheet are opened and their respective object references
are stored in the variables defined in the declaration section.

Closing the Workbook

Something to remember for later coding is that after you have opened and manipulated a workbook, you should close it
using the Close method. The workbook object close method releases the workbook for

< previous page

page_175

next page >

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->