Workbooks (collection)

<< Click to Display Table of Contents >>

Workbooks (collection)

Access path: Application à Workbooks

 1  Description

The Workbooks collection contains all open documents. The individual elements of this collection are of the type Workbook.

 2  Access to the collection

There is exactly one instance of the Workbooks collection during the whole runtime of PlanMaker. It is accessed through Application.Workbooks:

' Show the number of open documents

MsgBox pm.Application.Workbooks.Count

 

' Show the name of the first open document

MsgBox pm.Application.Workbooks(1).Name

 3  Properties, objects, collections and methods

Properties:

Count R/O

 

Objects:

Item Workbook (default object)

Application Application

Parent Application

 

Methods:

Add

Open

Close

Count (property, R/O)

Data type: Long

Returns the number Workbook objects in the collection, i.e. the number of the currently open documents.

Item (pointer to object)

Data type: Object

Returns an individual Workbook object, i.e. an individual open document.

Which Workbook object you get depends on the value that you pass to Item. You can specify either the numeric index or the name of the desired document. Examples:

' Show the name of the first document

MsgBox pm.Application.Workbooks.Item(1).FullName

 

' Show the name of the document "Test.pmdx" (if currently open)

MsgBox pm.Application.Workbooks.Item("Test.pmdx").FullName

 

' You can also use the full name with path

MsgBox pm.Application.Workbooks.Item("c:\Documents\Test.pmdx").FullName

Application (pointer to object)

Returns the Application object.

Parent (pointer to object)

Returns the parent object, i.e. Application.

Add (method)

Creates a new empty document, based either on the standard document template Normal.pmvx or any other document template you specify.

Syntax:

 Add [Template]

Parameters:

Template (optional; type: String): Path and file name of the document template on which your document should be based. If omitted, the standard template Normal.pmvx will be used.
If you omit the path or give only a relative path, PlanMaker's default template path will be automatically prefixed. If you omit the file extension .pmvx, it will be automatically added.

Return type:

Object (a Workbook object that represents the new document)

Example:

Sub Example()

 Dim pm as Object

 Dim newDoc as Object

 

 Set pm = CreateObject("PlanMaker.Application")

 pm.Visible = True

 Set newDoc = pm.Workbooks.Add

 MsgBox newDoc.Name

End Sub

You can use the Workbook object returned by the Add method like any other document. You can also ignore the return value of Add and get the new document from ActiveWorkbook.

Open (method)

Opens an existing document.

Syntax:

 Open FileName, [ReadOnly], [Format], [Password], [WritePassword], [Delimiter], [TextMarker]

Parameters:

FileName (type: String): Path and file name of the document or document template to be opened.
ReadOnly (optional; type: Boolean): Indicates whether the document should be opened only for reading.
Format (optional; type: Long or PmSaveFormat): The file format of the document to be opened. The possible values are:

 pmFormatDocument         =  0 ' PlanMaker document

 pmFormatTemplate         =  1 ' PlanMaker document template

 pmFormatExcel97          =  2 ' Excel 97/2000/XP

 pmFormatExcel5           =  3 ' Excel 5.0/7.0

 pmFormatExcelTemplate    =  4 ' Excel document template

 pmFormatSYLK             =  5 ' Sylk

 pmFormatRTF              =  6 ' Rich Text Format

 pmFormatTextMaker        =  7 ' TextMaker (= RTF)

 pmFormatHTML             =  8 ' HTML document

 pmFormatdBaseDOS         =  9 ' dBASE database with DOS character set

 pmFormatdBaseAnsi        = 10 ' dBASE database with Windows character set

 pmFormatDIF              = 11 ' Text file with Windows character set

 pmFormatPlainTextAnsi    = 12 ' Text file with Windows character set

 pmFormatPlainTextDOS     = 13 ' Text file with DOS character set

 pmFormatPlainTextUnix    = 14 ' Text file with ANSI character set for UNIX, Linux, FreeBSD

 pmFormatPlainTextUnicode = 15 ' Text file with Unicode character set

 pmFormatdBaseUnicode     = 18 ' dBASE database with Unicode character set

 pmFormatPlainTextUTF8    = 21 ' Text file with UTF8 character set

 pmFormatMSXML            = 23 ' Excel 2007 and later

 pmFormatMSXMLTemplate    = 24 ' Excel document template 2007 and later

 pmFormatPM2008           = 26 ' PlanMaker 2008 document

 pmFormatPM2010           = 27 ' PlanMaker 2010 document

 pmFormatPM2012           = 28 ' PlanMaker 2012 document

 pmFormatPM2012Template   = 29 ' PlanMaker 2012 document template

If you omit this parameter, the value pmFormatDocument will be assumed.
Tip: Independent of the value for the FileFormat parameter PlanMaker always tries to determine the file format by itself and ignores evidently false inputs.
Password (optional; type: String): The read password for password-protected documents. If you omit this parameter for a password-protected document, the user will be asked to input the read password.
WritePassword (optional; type: String): The write password for password-protected documents. If you omit this parameter for a password-protected document, the user will be asked to input the write password.
Delimiter (optional; type: String): Indicates the text delimiter (for text file formats), for example, comma or semicolon. If you omit this parameter, tabs will be used as a delimiter.
TextMarker (optional; type: Long or PmImportTextMarker): Indicates the characters the individual text fields are enclosed with (for text file formats). The possible values are:

 pmImportTextMarkerNone       = 0 ' No marker

 pmImportTextMarkerApostrophe = 1 ' Apostrophe marks

 pmImportTextMarkerQmark      = 2 ' Quotation marks

Return type:

Object (a Workbook object which represents the opened document)

Examples:

' Open a document

pm.Workbooks.Open "c:\docs\test.pmdx"

 

' Open a document only for reading

pm.Documents.Open "c:\docs\Test.pmdx", True

Close (method)

Closes all currently open documents.

Syntax:

 Close [SaveChanges]

Parameters:

SaveChanges (optional; type: Long or SmoSaveOptions) indicates whether the documents which were changed since they were last saved should be saved or not. If you omit this parameter, the user will be asked to indicate it (if necessary). The possible values for SaveChanges are:

 smoDoNotSaveChanges = 0      ' Don't ask, don't save

 smoPromptToSaveChanges = 1   ' Ask the user

 smoSaveChanges = 2           ' Save without asking

Return type:

none

Example:

' Close all open documents without saving them

pm.Workbooks.Close smoDoNotSaveChanges