Results 1 to 8 of 8

Help Deciphering VB module

Threaded View

  1. #1
    Registered User
    Join Date
    05-25-2015
    Location
    london
    MS-Off Ver
    2007
    Posts
    54

    Help Deciphering VB module

    Hi all,

    I have been set a task that involves modifying the way that a macro works for a client.. whilst I know how to do what i want to do, i do not know how to get excel to do it for me, so I will be learning VBA over the coming days

    My first step is to understand what the author has written in the first place so I know what I'm working with.

    I have annotated the code to try to explain what I think its saying.

    would someone be willing to give up a little time to check my annotations and expand upon anything that I haven't understood or have missed? the simplicity of my annotations should be a good indication of my level; of experience in VBA (close to zero)?

    This is what I have so far, I'll work on the other modules as the days pass..... The whole program takes a .csv file and converts it to a .xlsx file and organises data in a meaningful way and plots a graph from it (the graph has a zoom function too) and certain points of interest are read from the graph and reported in numbers.

    There is probably a fair bit that I haven't understood, so help would be great and really appreciated!

    I have crossposted this message on another forum - https://www.mrexcel.com/forum/excel-...=1#post5125039

    my comments follow '-JS-

    is it easier to upload my workbook?

    Option Explicit
    
    
    Sub Open_CSVs()
    
    
        Dim FSO As Scripting.FileSystemObject
        Dim FSO2 As Object
        Dim MyFolder As String
        Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
        Dim r As Long
        Dim MyFile As String
        
        Application.ScreenUpdating = False '-JS- suspend screen updating
        
    If Range("Source").Value = "" Then '-JS- "source" is the range in which the root directory is specified by the user
        MyFolder = GetFolder("C:\") '-JS- If no root directory was specified, the default will be C:\
    Else
        MyFolder = GetFolder(Range("Source").Value) '-JS- If root directory is specified, specification is prioritised
    End If
    
    
    ThisWorkbook.VBProject.VBComponents("Graph_Scaling").Export (MyFolder & "\Graph_Scaling.bas") '-JS- Exports The rescaling module as a .bas file (to the root directory?)
             
       Set FSO = New Scripting.FileSystemObject '-JS- Sets abbreviation for access to file system object functions
        Set SourceFolder = FSO.GetFolder(MyFolder) '-JS- Source folder is set as the root directory (with file system object functions enabled)
        For Each SubFolder In SourceFolder.SubFolders
            MyFile = Dir(SubFolder.Path & "\Exports\*.csv") '-JS- sets "MyFile" as the .csv file within each sub-sub-folder ("Exports") in the source folder.
    
    
    '-JS- I think this section searches for a folder called exports and converts a .csv file to a .xslsb file,
    '     then it processed the file by calling another subroutine ("show bounce" which is within the previously exported module "graph_scaling"),
    '     then continues this process for any nyumber of folders in the root directory.
    
    
            Do While MyFile <> "" '-JS- If files DO NOT exist, then do the following
                On Error GoTo Done '-JS- If files DO exist, then skip to "Done" (~16 lines below)
                Set FSO2 = CreateObject("scripting.filesystemobject")
                If FSO2.FileExists(SubFolder.Path & "\Exports\" & Replace(MyFile, "csv", "xlsb")) = True Then GoTo Done '-JS- Convert .csv file to .xslb, but is both already exist, then go to "Done"
                DoEvents '-JS- awaits completion of previous task before proceeding
                Workbooks.Open (SubFolder.Path & "\Exports\" & MyFile) '-JS- open the .xlsb workbook
                DoEvents '-JS- wait till workbook is open before proceeding
                
                Do While ActiveWorkbook.Name <> MyFile
                    Application.Wait Now + TimeValue("00:00:01") '-JS- Once the workbook is opne, wait this length of time before proceeding
                    DoEvents
                    Workbooks(MyFile).Activate '-JS- Once the workbook is open, ensure it is the active workbook
                    
                Loop
                DoEvents
                ActiveWorkbook.VBProject.VBComponents.Import (MyFolder & "\Graph_Scaling.bas") '-JS- Imports the module into the active workbook, presumably so that the subroutine within it cal ne applied to the active workbook.
                Call show_bounce '-JS- calls and runs the sub "show bounce"
                ActiveWorkbook.SaveAs SubFolder.Path & "\Exports\" & Replace(MyFile, ".csv", ""), FileFormat:=50 '-JS- saves processed file as a macro enabled .xslb file
                DoEvents
                Workbooks(Replace(MyFile, "csv", "xlsb")).Close False
    Done: '-JS- If files DO exist, then do the following
                On Error GoTo 0 '-JS- If an error occurs, then ignore it
                MyFile = Dir
            Loop
        Next SubFolder
        
        Kill (MyFolder & "\Graph_Scaling.bas")
        Set SubFolder = Nothing
        Set SourceFolder = Nothing
        Set FSO = Nothing
        
        Application.ScreenUpdating = True '-JS- resore screen updating
    
    
    End Sub
    Last edited by jjjjjjjjunit; 08-15-2018 at 01:32 PM. Reason: To inform of cross posting

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Deciphering VBA
    By jp45 in forum Excel General
    Replies: 2
    Last Post: 02-01-2017, 12:24 PM
  2. [SOLVED] Help Deciphering formula?
    By bbecht01 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-14-2013, 10:30 PM
  3. Deciphering a Formula
    By Winstonwolf in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-29-2012, 04:05 PM
  4. Deciphering a formula
    By MarginofBuffett in forum Excel General
    Replies: 1
    Last Post: 11-15-2010, 04:05 AM
  5. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  6. Another one i need deciphering...
    By Dan Mackman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-26-2007, 06:04 PM
  7. Deciphering two formulas
    By tylerpat7 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-28-2005, 04:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1