Oggetto Application - VBA Excel Tutorial Italiano 31

Edoardo Midali
3 Jun 202311:54

Summary

TLDRIn this VBA tutorial, the focus shifts to integrating Excel with VBA by exploring various objects available in VBA and Excel. The application object is introduced as a gateway to the entire Excel application, offering numerous properties and methods. The video delves into using Active properties to interact with the active cell, sheet, printer, and more. It also discusses modifying global application settings like alerts and the status bar, and concludes with a practical example of automating report formatting and email sending using the application object.

Takeaways

  • 📚 The video is a VBA tutorial focusing on integrating with Excel and its various components.
  • 👀 Introduction to Excel's Application object, which provides access to the entire Excel application.
  • 🛠️ Explanation of the Application object's extensive properties and methods, with examples like Name, Version, and Path.
  • 🔍 Discussion on how to use Application object to check user permissions and version for macro execution.
  • 📝 Utilization of Active properties to interact with the active cell, chart, printer, sheet, window, and workbook.
  • 🔑 Access and manipulation of the active workbook's password protection through the Application object.
  • 🎛️ Control over display settings such as alerts, comment indicators, formula bar, and status bar via the Application object.
  • 📧 Demonstration of using the Application object to send an email with an attached file through Outlook.
  • 🔄 Emphasis on the global impact of changes made through the Application object and the need to reset them after specific macros.
  • 📊 Highlight of the practical applications of VBA, such as automating report formatting and email sending for regular updates.
  • 🚀 Preview of upcoming tutorials on additional Excel objects like Workbook and Worksheet in future videos.

Q & A

  • What is the main focus of episode 31 of the VBA course?

    -The main focus of episode 31 is to delve into the integration aspects between VBA and Excel, specifically looking at the various objects available in VBA and Excel.

  • What does the Application object in Excel VBA provide access to?

    -The Application object in Excel VBA provides access to the entire Excel application. It has numerous properties and methods that can be utilized for different tasks.

  • How can you retrieve the name of the active sheet using VBA?

    -You can retrieve the name of the active sheet using the following code: `ActiveSheet.Name`.

  • What is the purpose of the Application object's properties like ActivePrinter and ActiveCell?

    -The properties like ActivePrinter and ActiveCell allow you to interact with and control the current active printer and cell within the Excel application, which can be useful for automating tasks and creating dynamic scripts.

  • How can you check the version of Microsoft Excel using VBA?

    -You can check the version of Microsoft Excel using VBA by using the following code: `Application.Version`.

  • What is the significance of the Application object's DisplayAlerts property?

    -The DisplayAlerts property of the Application object controls whether alert messages are displayed to the user during the execution of macros. It can be temporarily turned off to prevent interruptions during macro execution.

  • How can you use the Application object to control the display of certain elements in Excel?

    -You can use the Application object's properties, such as DisplayFormulaBar, DisplayStatusBar, and DisplayCommentIndicator, to control the display of the formula bar, status bar, and comment indicators, respectively.

  • What is the Collection of objects in Excel VBA?

    -The Collection of objects in Excel VBA refers to a group of related objects that can be accessed and manipulated as a unit, such as Workbooks, Worksheets, and Windows.

  • How can you directly access the active workbook's password property using the Application object?

    -You can directly access the active workbook's password property using the following code: `Application.Workbooks(1).Password`.

  • What is the practical application of using the Application object to send an email with an attached file?

    -The practical application of using the Application object to send an email with an attached file is to automate the process of formatting reports and sending them to specified recipients without manual intervention, saving time and reducing the risk of errors.

  • How can you use the Application object to display a dialog box in Excel VBA?

    -You can use the Application object's Dialogs property to display a dialog box in Excel VBA. For example, `Application.Dialogs(xlDialogOpen).Show` will display the 'Open' dialog box.

Outlines

00:00

📘 Introduction to Excel VBA Integration

This paragraph introduces the 31st episode of a VBA course, focusing on the integration aspects with Excel. It begins by discussing the introduction of Excel VBA, object-oriented programming, and other related concepts. The speaker then explains the broad scope of Visual Basic and its integration with Excel. The paragraph highlights the importance of the Application object, which provides access to the entire Excel application, and discusses various properties and methods associated with it. The speaker also touches on practical scenarios where accessing basic information about the application can be helpful, such as controlling user permissions and handling different Excel versions for macros.

05:01

📘 Utilizing Active Properties and Methods

This paragraph delves into the use of Active properties and methods within the Excel VBA environment. The speaker explains how to access and manipulate various active components such as cells, charts, printers, sheets, and workbooks. The paragraph emphasizes the versatility of the Application object in accessing and modifying the state of the active elements in Excel. It also discusses the practical applications of these properties, such as creating graphical interfaces, managing print settings, and altering the status bar. The speaker provides examples of how these properties can be utilized to enhance the functionality and user experience of Excel applications.

10:03

📘 Advanced VBA Techniques and Outlook Integration

The final paragraph of the script explores advanced VBA techniques, including the use of the Application object to control display settings and interact with Outlook. The speaker demonstrates how to disable alerts, manage comment indicators, and modify the status bar to improve the user experience. The paragraph also showcases how VBA can be used to automate tasks, such as sending emails through Outlook using the Application object. The speaker provides a practical example of automating the formatting and sending of reports, highlighting the efficiency and convenience of using VBA for repetitive tasks.

Mindmap

Keywords

💡Excel VBA

Excel VBA (Visual Basic for Applications) is a programming language used for creating and automating tasks within Microsoft Excel. It is a core concept in the video, which discusses using VBA to integrate and automate various Excel functionalities. The video provides an in-depth look at how VBA can be used to control and customize the Excel environment, making it a powerful tool for managing and processing data.

💡Application Object

The Application object in Excel VBA refers to the instance of the Excel application itself. It is the primary object that provides access to all other objects and features within Excel. The video emphasizes the Application object's extensive properties and methods, which can be utilized to control the Excel environment, check the version, and manage permissions, among other tasks.

💡Active Properties

Active properties in Excel VBA refer to the currently selected or active object within the Excel interface. These properties allow users to interact with the object that is in focus, such as the active cell, active sheet, or active workbook. The video highlights the importance of active properties for automation scripts that need to perform actions on the currently selected data or object.

💡Macros

Macros in Excel are automated sequences of instructions that perform a specific task or set of tasks. They are a critical component of VBA programming, allowing users to create custom functions and processes to streamline data management and manipulation. The video discusses how macros can be controlled and customized using VBA, including modifying macros to work with different Excel versions or user permissions.

💡User Permissions

User permissions in the context of Excel VBA refer to the access rights and restrictions set for different users of the application. These permissions can control which features or macros a user can access and execute. The video script discusses using the Application object to check user permissions, which is essential for ensuring that only authorized users can run specific macros or access certain data.

💡Version Compatibility

Version compatibility in the context of Excel VBA refers to the ability of a macro or a script to function correctly across different versions of Excel. It is crucial for ensuring that macros can be executed without errors or modifications, regardless of the user's Excel version. The video emphasizes the importance of checking the Excel version through the 'Application.Version' property to tailor macros to specific versions.

💡Worksheets and Workbooks

Worksheets and workbooks are fundamental components of Excel. A workbook is a file containing one or more worksheets, which are the individual pages within the workbook where data is entered and manipulated. In Excel VBA, these objects can be accessed and manipulated using VBA code. The video script discusses using VBA to interact with these objects, such as retrieving the name of the active worksheet or workbook, and emphasizes their importance in automating Excel tasks.

💡Printing and Display Settings

Printing and display settings in Excel pertain to the configurations that determine how Excel outputs data to a printer and how it presents information on the screen. The video script discusses using VBA to control these settings, such as hiding alerts, managing the status bar, and displaying comment indicators. These settings can be crucial for creating professional reports and customizing the user experience.

💡Automation in Reporting

Automation in reporting refers to the process of creating and executing macros or scripts that can automatically generate, format, and send reports. This is a key theme in the video, which discusses using Excel VBA to automate repetitive report generation tasks, saving time and reducing errors. The video provides an example of automating the preparation and sending of weekly and monthly reports to different recipients.

💡Dialog Boxes

Dialog boxes in Excel are pop-up windows that allow users to interact with the application, providing inputs or receiving information. In the context of Excel VBA, dialog boxes can be programmed to appear and collect user inputs or display messages. The video script mentions using the 'Application.Dialogs' object to show and manage these dialog boxes, which can be useful for creating custom user interactions within a VBA project.

Highlights

Introduction to Excel's integration with VBA, focusing on the Application object and its extensive properties and methods.

Accessing the Application object gives you control over the entire Excel application.

Using the Application object to retrieve the name and version of the Excel application.

Checking the user's identity and permissions using the Application object's properties.

Utilizing Active properties to interact with the active cell, chart, printer, sheet, window, and workbook.

Retrieving and modifying the active sheet and workbook names directly through the Application object.

Accessing and modifying the active workbook's password protection settings.

Controlling the display of various Excel elements, such as alerts, comment indicators, and the formula bar.

Customizing the status bar display, including zoom level and sheet information.

Globally changing application settings and remembering to revert them after specific macros.

Using the Application object to display and interact with dialog boxes, such as Outlook's mail sending feature.

Automating the formatting and sending of reports via email using VBA macros.

Practical example of automating the preparation and sending of weekly and monthly reports to a commercial accountant.

Exploring the potential of the Application object in automating routine tasks and improving efficiency in Excel.

Understanding the collection of objects available in VBA and Excel, such as Workbooks, Worksheets, and Windows.

Looking forward to exploring more about the Workbook object in the next video.

Transcripts

play00:00

episodio 31 del corso di vba oggi

play00:03

comincia il modulo dedicato a guardare

play00:06

nel dettaglio quelle che sono le parti

play00:09

di integrazione con Excel quindi nella

play00:12

prima parte abbiamo introdotto Excel bba

play00:16

programmazione ad oggetti eccetera nella

play00:18

seconda parte abbiamo visto la

play00:20

programmazione non per intero perché

play00:22

Visual Basic è molto ampio però abbiamo

play00:25

visto tutto ciò che ci può servire per

play00:27

cominciare a programmare in questa terza

play00:29

fase lavoriamo appunto con i vari

play00:31

oggetti che abbiamo a disposizione tra

play00:33

vba ed Excel Il primo è l'application

play00:36

object con l'application object abbiamo

play00:39

letteralmente accesso a tutto perché se

play00:43

ci pensate l'application object è

play00:44

l'oggetto riguardante l'intera

play00:47

applicazione ora application object vi

play00:49

faccio vedere ha veramente tante tante

play00:52

tante proprietà e metodi non le vediamo

play00:55

tutte ma vi voglio far capire Più o meno

play00:57

la mentalità con cui approcciare questo

play00:58

oggetto vi faccio vedere Allora

play01:00

innanzitutto mettiamo qua il punto di

play01:02

domanda Se io faccio application punto

play01:04

name TAC vedete ottengo Microsoft Excel

play01:07

andiamo avanti facciamo punto version

play01:10

otteniamo la versione di Microsoft Excel

play01:13

andiamo con magari Pes vedete quindi è

play01:16

il percorso in cui è lanciato Excel e

play01:20

poi ad esempio Potremmo avere username

play01:23

TAC queste sono solo alcune delle

play01:26

proprietà che possiamo guardare con

play01:29

application perché effettivamente

play01:31

application è tutto Excel è il programma

play01:34

che sta andando Uno potrebbe dirmi da

play01:37

cosa serve questa cosa qua Beh poniamo

play01:39

il caso che magari volete controllare

play01:42

l'utente se l'utente non siete voi o

play01:44

qualcun altro Volete dare tipi di

play01:46

permessi diversi quindi se l'utente non

play01:48

è quello non può utilizzare ad esempio

play01:51

certi tipi di Macro oppure se la

play01:54

versione è diversa andiamo a fare una

play01:56

macro leggermente

play01:58

modificata perché magari la versione

play02:00

precedente non gestisce determinato

play02:03

operazioni e via discorrendo Oppure

play02:05

vogliamo assicurarci che sia Microsoft

play02:07

Excel e non un'altra applicazione perché

play02:09

magari è una macro che possiamo lanciare

play02:12

su più applicazioni

play02:14

Office ma vogliamo essere sicuri che sex

play02:16

Fai questo se è World fai quest'altro

play02:19

Quindi ci possa essere situazioni in cui

play02:21

avere accesso alle informazioni basiche

play02:24

della nostra application può essere

play02:26

d'aiuto per fare un altro esempio invece

play02:28

potremmo andare a prendere prendo la

play02:31

cella Attiva scrivo qwerty vi faccio

play02:33

vedere abbiamo tutta una serie di Active

play02:35

proprietà vedete Active cell Active

play02:38

chart Active printer e quant'altro

play02:41

cominciamo magari con Active printer vi

play02:43

faccio vedere questa è la mia stampante

play02:44

Ad esempio in questo caso se stiamo

play02:47

andando a creare un'interfaccia grafica

play02:48

e poi le vedremo come crearle se andiamo

play02:51

a creare un'interfaccia grafica Dove

play02:52

possiamo selezionare le stampanti

play02:54

possiamo andare a fare una cosa del

play02:56

genere quindi dobbiamo utilizzare le

play02:59

pennette a disposizione questa è la

play03:01

stampante Attiva Oppure potrei andare a

play03:03

prendere Active cell e andare a prendere

play03:06

il valore se faccio invio Scusatemi Sono

play03:09

sulla cella sbagliata Se faccio invio

play03:11

vedete che ottengo qwerty così come

play03:13

Active cell e printer ci sono tanti

play03:15

Active a cui possiamo fare riferimento

play03:16

Guardate Active sheet quindi il foglio

play03:19

attivo che è il foglio 1 Active Windows

play03:21

quindi potrei avere più finestre Active

play03:23

workbook che cosa ci possono servire ad

play03:26

esempio prendiamo Active shit Active

play03:30

sheet punto name e vi faccio vedere che

play03:32

è il nostro foglio 1 voi Mi potreste

play03:34

dire Sì Edo me ci possa arrivare anche

play03:36

tramite

play03:37

worksheets prendo l'uno punto name TAC e

play03:42

ci arrivo Qual è il discorso che qua

play03:44

siamo passati dalla Collection ed è una

play03:46

situazione in cui ci può servire passare

play03:48

dal World cioè prendiamo il name del

play03:51

primo workshop mentre invece da

play03:53

application andiamo direttamente su

play03:55

quello attivo va bene quindi una volta

play03:58

che prendiamo quello attivo abbiamo Sì

play04:00

un worshit ma siamo andati direttamente

play04:03

su quell'attivo Ok quindi sono due modi

play04:06

diversi qui facciamo application

play04:08

workbook workshit E poi prendo il name

play04:12

Qua invece andiamo diretti per Active

play04:14

sheet lo stesso concetto lo potete

play04:16

applicare letteralmente per la finestra

play04:19

la Windows e quant'altro vi faccio

play04:22

vedere se noi siamo qua potremmo fare

play04:23

Active workbook punto password vedete

play04:27

che abbiamo accesso alla password e

play04:29

potremo andarla a mettere per vedere le

play04:31

varie proprietà a cui potete passare

play04:33

direttamente tramite i vari Active le

play04:36

potete vedere qua se io premo sul foglio

play04:38

vedete foglio a queste proprietà il nome

play04:41

se vogliamo Mostrare i page Break In

play04:45

questo caso non ce li mostra oppure

play04:47

abbiamo mostra Right to left oppure

play04:51

Abilita auto Filter Abilita calcoli

play04:55

abilità formattazione condizionale

play04:57

eccetera eccetera come ci siamo qua o ci

play05:00

passiamo prendendo work sheets foglio 1

play05:02

oppure worships 1 oppure possiamo

play05:05

passare tramite Active workcit allo

play05:08

stesso modo cartella di lavoro che ha

play05:10

molte più cose vedete come ci possiamo

play05:13

arrivare ci possiamo arrivare tramite

play05:15

workbooks 1 oppure workbooks nome del

play05:18

progetto altrimenti vedete che qua c'è

play05:21

password dove sono passato sono passato

play05:23

da application Active workbook va bene

play05:26

quindi poi vedremo lo stesso giro quando

play05:29

lavoreremo con workbook E worksheet ma

play05:32

se volete saltare tutta la fila e

play05:34

prendere direttamente quella attivo lo

play05:36

potete fare da application un'altra cosa

play05:38

molto molto bella che possiamo fare

play05:40

tramite application e andare a

play05:41

disattivare e mostrare determinate

play05:44

situazioni ad esempio application punto

play05:47

display c'è una categoria enorme di

play05:51

display di cose che possiamo mandare a

play05:53

schermo o meno display alerts ad esempio

play05:56

ci permette di andare a nascondere

play05:58

quelle che sono le finestre di avviso

play06:00

ogni tanto vi posso comparire possiamo

play06:02

andarle a nascondere è importante sapere

play06:05

che però se le attivate qua dentro Cioè

play06:07

se fate display Alert Falls per una

play06:10

particolare macro dovete poi riattivarla

play06:12

Quindi se voi fate Così giusto per

play06:14

andare a fare un qualcosa nella macro

play06:16

senza che l'utente venga Stoppato nella

play06:19

macro Perché chiaramente la finestra

play06:21

di Alert va a stoppare la macro dovete

play06:24

poi ricordarvi di riattivarla Quindi se

play06:26

le volete di default dovete ricordarvi

play06:28

di riattivarle perché perché altrimenti

play06:30

se voi non mettete questo True da qua

play06:33

non importa se l'avete utilizzato una

play06:34

volta in una sola macro tutta

play06:36

l'applicazione avrà Disattivati gli

play06:39

alert OK e quindi un problema perché

play06:41

alcune volte gli alert servono quindi

play06:43

Ricordatevi questo concetto perché si

play06:45

applica anche ad altre cose che vediamo

play06:47

ad esempio se io vado qua e faccio

play06:49

display comment indicator per ora non

play06:52

faccio niente ma Vi mostro che se vado

play06:54

qui vado su nuovo commento scrivo

play06:57

qualcosa faccio invio vedete che abbiamo

play06:59

qua il segnalino viola del commento se

play07:03

vado a fare display comment indicator

play07:05

posso andare a mettere no indicator F5 e

play07:09

vedete che è scomparso il commento però

play07:11

c'è lo stesso perché se faccio tasto

play07:13

destro vedete Elimina commento rispondi

play07:15

a commento se vado sotto Ho solo nuovo

play07:18

commento di conseguenza se io torno qua

play07:20

e faccio True Facciamo così F5 vedete

play07:25

che è tornato il commento quindi la

play07:27

stessa cosa che possiamo fare per

play07:29

display comment indicator la possiamo

play07:32

fare per una serie di proprietà giusto

play07:37

per spiegarvi questo concetto facciamo

play07:39

vedere qualcos'altro abbiamo la formula

play07:41

bar che è questa qua in alto oppure

play07:42

possiamo andare a mettere la status bar

play07:46

che è questa qua sotto vedete sotto i

play07:48

fogli c'è questa barrettina qua sotto

play07:51

dove vado a modificare lo zoom ad

play07:54

esempio faccio display status bar uguale

play07:58

io faccio x e se faccio F5 vedete che è

play08:02

scomparsa se vado a rimettere True la

play08:05

faccio ricomparire per farvi capire come

play08:07

con display Stiamo andando a modificare

play08:09

delle parti importanti dell'applicazione

play08:12

possiamo veramente andare a cambiare

play08:14

l'applicazione a piacimento Ricordatevi

play08:18

però che queste cose hanno una valenza

play08:21

globale Perciò se lo fate per un caso

play08:25

specifico dovete poi ricordarvi di

play08:28

riattivarle altrimenti resta sempre così

play08:32

Va bene poi Un'ultima cosa che ci può

play08:35

interessare cioè con application al

play08:37

momento non lavoreremo tantissimo e per

play08:38

farvi capire che tipi di proprietà

play08:40

possiamo andare a modificare Abbiamo

play08:42

un'ultima cosa molto divertente che

play08:44

daialox questo è molto divertente Ve

play08:47

l'ho inserito perché lo trovo molto

play08:49

bello io vedo qua in dialox e vedete che

play08:52

abbiamo una serie di dialoghi di dialog

play08:54

sono le finestre che compaiono e abbiamo

play08:56

una serie di dialog che possiamo

play08:59

voglio mostrare quindi qualsiasi tipo di

play09:01

finestra che vi può comparire su Excel

play09:04

la possiamo effettivamente far comparire

play09:07

noi a mano in qualsiasi momento vedete

play09:09

Quante sono sono tutte Praticamente ci

play09:11

sono tutte copie paste activate

play09:14

onlinement e via discorrendo Io voglio

play09:16

concentrarmi su XL Daia log mail Send

play09:21

mail Ecco qui e poi vado a fare show per

play09:26

mostrarlo e dentro vado a mettere vedete

play09:28

che abbiamo una serie di argomenti

play09:29

giusto vado a capo affinché ci stiamo

play09:32

dentro come argomento uno Voglio andare

play09:35

a mettere la mail a cui mandarlo

play09:37

Facciamo così mando la mail a cui

play09:38

mandarlo in questo caso mettiamo una

play09:40

mail a caso che è qwerty at

play09:43

quientissimo punto acurtissimo punto it

play09:47

molto bene Poi virgola argomento due Ops

play09:51

ho sbagliato qua devo mettere i due

play09:53

punti argomento 2 TAC TAC e qua dentro

play09:56

posso andare a mettere l'oggetto una

play09:59

mail oggetto della mail se faccio così

play10:03

vedete come si è aperta automaticamente

play10:05

una finestra di messaggio di Outlook

play10:07

questo perché io ho Outlook installato

play10:10

già connesso qua vedete che ho messo una

play10:11

mela a caso giusto per nascondere

play10:13

l'indirizzo mail ma se Guardate invece a

play10:15

chi la sto mandando kurticurtitissimo è

play10:18

quello che ho messo qua sopra e come

play10:20

oggetto oggetto oggetto della mail e ciò

play10:22

che avevo qua sopra Fateci caso stiamo

play10:24

inviando direttamente il file qua quindi

play10:28

potreste avere e questo è un esempio

play10:30

molto pratico e molto bello per questo

play10:31

ve l'ho inserito possiamo avere una

play10:34

macro che automaticamente magari va a

play10:38

fare una formattazione eccetera e

play10:40

automaticamente la va a inviare quindi

play10:41

pensate Se avete dei report che dovete

play10:44

mandare giornalmente settimanalmente a

play10:46

diverse persone formattati in diversi

play10:49

modi Penso ad esempio quando io faccio

play10:51

dei documenti per il mio commercialista

play10:53

me li chiede mi chiede certi documenti

play10:55

settimanali certi documenti mensili o

play10:59

sacro che Format ne vanno a prendere

play11:01

dati in un certo modo Quindi prende la

play11:02

lista delle fatture settimanalmente

play11:04

vuole qualcosa mensilmente vuole

play11:05

qualcos'altro automaticamente prende i

play11:07

dati che io vado a registrare delle

play11:09

fatture me li va a formattare in diversi

play11:12

file e poi li va a inviare Ok una cosa

play11:16

del genere la faccio utilizzando

play11:18

application stylox che poi attorno c'è

play11:21

tutt'altro delle cose che abbiamo visto

play11:22

di formattazione eccetera però alla fine

play11:24

io passo da qua Una volta che controllo

play11:27

tutto faccio un check faccio invia e la

play11:30

mail arriva al commercialista ok Quindi

play11:32

questo è proprio un esempio classico

play11:34

forse più pratico il più realistico tra

play11:39

ciò che potevo portarvi perché lo uso

play11:41

anch'io direi che con l'oggetto

play11:43

application è tutto noi nel prossimo

play11:46

video guardiamo l'oggetto workbook che

play11:49

fa parte della Collection workbox

play11:51

eccetera eccetera ma ci arriviamo nel

play11:52

prossimo video A tra poco

Rate This

5.0 / 5 (0 votes)

Related Tags
Excel VBAObject IntegrationApplication ObjectMacro ProgrammingSoftware AutomationOffice DevelopmentWorkflow OptimizationUser PermissionsInteractive TutorialProgramming Techniques