Excel-Lent

 Going Beyond Basics    

esto curiosa (EC)  : Stay Curious

responsum (R) : Answer

Tested in Microsoft Office 365 ProPlus (File->Account->About; MS Office for 365 MSO(16.0.12527.21490) 64 bit)

[02-14-2021]  First Working Excel Program

Q. (EC1) You are starting a new Excel Project. What is the quickest way to write a working VBA Excel Macro? 

A. (R1) Quickest way to create a working Macro is to write it in a Module & run the Module. 

-- Make sure you save your file with extension xlsm, else your macros will not get saved. This will require file->save as->Select 'xlsm' in the file type drop down.

-- Enable 'Immediate Window' by navigating to View->Immediate Window for viewing output of simple programs. This is the quickest way to see the fruits of you hard work!

-- Your First Program below reads content of a cell called 'FilePath' and prints the value in the 'Immediate Window'.

1+ Start with navigating to 'Formula' --> 'Name Manager' and create a new Formula Name 'FilePath'. 

2+ Go Back to Microsoft VBA and Write the following piece of code 

Sub MyFirstVBA()

Dim Fname As Variant

Fname = Range("FilePath").Value
Debug.Print Fname

End Sub

3+ Update the Cell referred to in the 'FilePath' variable with the text "TEST3"

4+ Run the Code and observe the output in the Immediate Window


 


No comments:

Post a Comment