Automating tasks using a programming language is a highly customized process. So, what if an automated task is not needed anymore? Will the code you wrote go in vain? Not exactly!!
Any big task can be broken into smaller subtasks. So, whenever you try to automate a new task, you can come up with a new algorithm, fine tune these subtasks to implement the new algorithm.
As far as VBA is concerned, following subtasks are very common:
- Opening/closing/renaming a file
- Searching a particular keyword in column headers (very crucial)
- Checking if a string is a part another string
- Checking if a directory is empty
- Deleting all the files present in a directory
- Converting a list of CSV files to XLSX files
- Finding last row number of a column (very crucial)
- Splitting an excel file into multiple files based on a criteria
- Combining multiple excel files into one file
- Creating IE, MS Word and, MS PowerPoint objects and working with them
- Converting a column letter to column number and vice-versa
- Clearing cell values in a particular range in an excel sheet
As you keep automating tasks, above list will keep growing. So never think that the effort behind an automated task, which is no longer in use, has been wasted.
Infact, next time when you automate a task, it is going to take lesser time than it did previously (assuming moderate complexity). You just need to understand the problem, come up with an algorithm, break it into subtasks and there you go (obviously some fine tuning is always needed).
Some undisputed tips which we all know (just reiterating):
- First think then write. Don't be in a hurry to write code.
- Do not write everything in main method ('submodule' in case of VBA)
- Make your code as modular as much possible
- Do not forget to use 'Option Explicit' in VBA (using it does not allow to use variables without declaring them)
- Avoid hard coding as much as possible (see attached)
- Dereference an object as soon as its use is over (In case of VBA for e.g. --> 'Set wkbsource = Nothing')
- Add proper error handling
- A good program will try to accommodate as many use cases as possible
- Always add COMMENTS!!
Happy Learning !!
hashtag#VulnerabilityManagement hashtag#Cybersecurity
No comments:
Post a Comment