Chapter 9. Drive and DriveApp

Native Office and Docs files are accessed by services specifically for that purpose from within both VBA and Apps Script. There are times that you may need to access other kinds of files directly from your Apps Script or VBA application. With VBA, you can access the local client machine’s filesystem to read and write supplementary files generated within the Office app.

Apps Script runs on Google servers so does not have access to the local client machine. Instead, these kinds of operations can be performed on Google Drive. However, if Drive client synchronization is enabled, reading and writing to Drive is essentially “accessing the client by proxy,” as any files written to Drive are copied to the client and vice versa.

Drive can be accessed in three ways from Apps Script, as outlined in Table 9-1.

Table 9-1. Ways of accessing Google Drive from Apps Script
Interface Description
DriveApp (Apps Script built-in service) A simplified service for accessing the most commonly used capabilities through simple data structures
Drive (Apps Script advanced Google service) Enables access to most of the Drive API capabilities, using the default (fairly complex) data structures.
Drive JSON API Rest API to all of the Drive API features accessible via UrlFetchApp. OAuth 2.0 authentication required.

Microsoft OneDrive

OneDrive is similar to Drive, has a JSON API, and uses OAuth 2.0 for authentication. You can access OneDrive from Apps Script using

Get Going GAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.