Code Monkey home page Code Monkey logo

ariellomoctos / vba-projects Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 31 KB

This repository contains all projects, coding standards, boilerplate, and best practices. This is intended to share my experience and expertise so everyone can fork or download everything from this repository even without permission. Happy Coding!

vba vba-automation vba-webscraping vba-sapscripting vba-forms vba-snippets coding-standards best-practices freelance-work

vba-projects's Introduction

Visual-Basic-For-Application-Projects

This repository contains all projects, coding standards, boilerplate, and best practices. This is intended to share my experience and expertise so everyone can fork or download everything in this repository even without permission.

VBA CODING STANDARDS AND BEST PRACTICES

  • Enable Option Explicit
    • This Forces explicit declaration of all variables in a file, or allows implicit declarations of variables.
  • Use Title blocks for each Macro
    • This title blocks will give you information about the module what it does and how it will be called.
        PROGRAM:         UpdateCustomerCur
        DESCRIPTION:     This is to update the list of customer currency in the database
        CALL:            Call thru Macro UpdateCustomerCur
  • Get Advantage of Modular Programming Technique

    • Modular programming is a software design technique that emphasizes seperating the functionality of a program into dependent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
    • Categorize and divide your code based from what it does and create one module for similar task. Follow Modular Programming technique due to its advantage when refactoring and scaling your code. Also, it will give you less headache when you're debugging your code, easy to understand, and really helpful for big and complex projects.
  • Declaring Constants and Variables

    • The scope of a variable in Excel VBA determines where that variable may be used. You determine the scope of a variable when you declare it. There are three scoping levels: procedure level, module level, and public module level.
    • Make use the advantage of declaring variables based from scope (i.e. Local, Module, Public)
    • Constants are coded in ALL_UPPER_CASE with words seperated by underscores.
    Global Const WDGT_STATUS_OK = 0
    Global Const WDGT_STATUS_BUSY = 1
    Global Const WDGT_STATUS_FAIL = 2
    Global Const WDGT_STATUS_OFF = 3
    Global Const WDGT_STATUS_START = 4
    Global Const WDGT_STATUS_STOP = 5
  • Naming Convention for SubProcedures and Functions >>> VERB.NOUN.ADJECTIVE
    Sub UpdateCustomerCur()
      'Code goes here
    End Sub
  • Use HungarianNotation for Variables, Constants, SubProcedures and Functions
    • Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind, and in some dialects its type. The original Hungarian Notation uses intention or kind in its naming convention and is sometimes called Apps Hungarian as it became popular in the Microsoft Apps division in the development of Word, Excel and other apps. As the Microsoft Windows division adopted the naming convention, they used the actual data type for naming, and this convention became widely spread through the Windows API; this is sometimes called Systems Hungarian notation.
      Dim strMyName As String
      Dim intMyNumber As Integer
DECLARING VARIABLES
        VARIABLE       TAG             NOTES
        BOOLEAN        bln             blnFound
        BYTE           byt             bytRasterData
        CURRENCY       cur             curRevenue
        DATE (Time)    dat             datStart
        DOUBLE         dbl             dblTolerance
        ENUM           enm             enmColours
        INTEGERS       int             intQuantity
        LONG           lng             lngDistance
        SINGLE         sng             sngAverage
        STRING         str             strCustName
        USERDEFINED    udt             udtEmployee
        Variant        var             varCheckSum

OTHER PREFIXES
        cbo ComboBox
        chk CheckBox
        cmd CommandButton
        frm Form
        img Image
        lbl Lable
        lst ListBox
        rpt Report
        shp Shape
        txt TextBox
        tbl Table
        ole OLE Control
        pic Picture
        pnl Panel
        qry Query

        Db Database
        ws Workspace
        rs Recordset
        xl Excel Object
        wd Word Object

Data-Evidence-Collector

A Microsoft Excel Application using Visual Basic for Application (VBA) programming to web scrape documents and extract supporting documents. Note: This project won't run without a "private" application installed/accessed. However, web scraping techniques and codes used in this project could serve as reference for other developers.

Data-Evidence-Collector-Screenshot Click to Download: https://drive.google.com/file/d/1DI0cC_ip_8U7BKuoLiNZoqZ2hYzUZMTr/view

OPEN INTERNET EXPLORER INSTANCE

Note: Setup Library Reference: Ctrl+F11 > Tools > References > Find/Tick: Microsoft HTML Object Library, Microsoft Internet Controls

'Open Internet Explorer instance and ie as visible

Dim IE as InternetExplorerMedium
Set IE = New InternetExplorerMedium
IE.navigate "www.google.com"
IE.Visible = True

'Loop Until IE.Loading Readystate_Complete

Do Until IE.readyState = READYSTATE_COMPLETE
	DoEvents
Loop

CALL, ACTIVATE, MANIPULATE HTML-TAG-ELEMENTS

'User Input
IE.document.getElementById("MainContent_txtRequestNumber").Value = "Text"

'Tick documents: Boolean (True or False)
IE.document.getElementById("MainContent_cbxGetInbox").Checked = False

'Click buttons:
IE.document.getElementById("MainContent_btnSearch").Click

'Wait / Run after some time
Application.Wait (Now + TimeValue("00:00:05"))

'Get value within html grid/table <td>
IE.document.getElementById("MainContent_grdSearch").getElementsByClassName("gridDataRow")(0).getElementsByTagName("td")(4).innerText

EXTRACT DOCUMENTS BASED FROM URL

Private Declare Function URLDownloadToFileA Lib "urlmon" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Function downloadfile(URL As String, LocalFilename As String) As Boolean
		Dim lngRetVal As Long
		lngRetVal = URLDownloadToFileA(0, URL, LocalFilename, 0, 0)
		If lngRetVal = 0 Then downloadfile = True
End Function

Sub DownloadFileWithURLlink()
	'URLlink, Filename
	downloadfile www.google.com/1fajf-fhd241d-1345f.docx, "wordfilename.docx"
End Sub

vba-projects's People

Contributors

ariellomoctos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sf-danielcalvo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.