Page 19 of 19 FirstFirst ... 9171819
Results 181 to 186 of 186

Thread: Appendix Thread 2. ( Codes for other Threads, HTML Tables, etc.)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Some screen shots for this post https://eileenslounge.com/viewtopic....313792#p313792











    ......Here a slightly simpler demo, just for Eileens Lounge..., but it’s a real example looking at one of the smaller Folders I have been wanting to investigate.
    To do it:
    Put the uploaded file, EileenMMDemo.xls, and this folder ,
    Movie Maker https://app.box.com/s/cxvc735a85q6az2r3gtb7ii9w2p3jzpf
    , in the same place. Then just open the file EileenMMDemo.xls. That file only has one worksheet so the workbook should show just one window of that. In that window make a selection towards the left. Now run the only available macro, Sub PassFolderForReocursing3() , in that workbook which is in the only code module. At the start of the macro it will use the ActiveCell of that window to try and get a single cell range object from the your window Selection . It usually manages that, and goes on to put some results out with that cell at top left. It should look something like this
    Attached Files Attached Files
    Last edited by DocAElstein; 01-27-2024 at 12:50 AM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Code:
    Private Sub ReoccurringFldItmeFolderProps3(ByVal Pf As String)
    Rem 0
     Let Reocopy = Reocopy + 1 ' Originally the variable  Reocopy  is zero.  It will become 1 on first entering the macro.  Every time we leave this macro, this number is reduced by 1   So in simple use it will be 1 or zero indicating that a copy is in use.  However, should this macro "Call itself", before its finished , ( the recursion idea ) then the value will be 2  and so on.  So effectively it tells us which copy is running at any time
    Rem 1
     'Set objWSO = New Shell32.Shell            '    https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg     https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
     Set objWSO = CreateObject("shell.application")
    'Dim objWSOFolder As Shell32.Folder: Set objWSOFolder = objWSO.Namespace((Pf))  '
    Dim objWSOFolder As Object: Set objWSOFolder = objWSO.Namespace((Pf))  '  (( ))  https://stackoverflow.com/questions/33868233/shell-namespace-not-accepting-string-variable-but-accepting-string-itself/77888851#77888851   https://microsoft.public.access.narkive.com/Jl55mts5/problem-using-shell-namespace-method-in-vba#post5
    Rem 2
    'Dim FldItm As Shell32.FolderItem
    Dim FldItm As Object
        For Each FldItm In objWSOFolder.Items ' ======= Main Loop ==================================================|
        ' Dim Clm As Long: ' Global variable
         Let Clm = Clm + 1
        Dim Rw As Long: Let Rw = Reocopy + 1
             Let MeActiveCell.Offset(Rw, Clm) = objWSOFolder.GetDetailsOf(FldItm, 0)
                If objWSOFolder.GetDetailsOf(FldItm, 2) = "Dateiordner" Then                '   GetDetailsOf(FldItm, 2)   tells me the type of the WSO item
                'Set objFSO = New Scripting.FileSystemObject     ' https://i.postimg.cc/d1GHPGxJ/Microsoft-Scripting-Runtime-Library.jpg
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                'Dim objFSOFolder As Scripting.Folder: Set objFSOFolder = objFSO.GetFolder(Pf & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                Dim objFSOFolder As Object: Set objFSOFolder = objFSO.GetFolder(Pf & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                 Let MeActiveCell.Offset(Rw + 1, Clm) = objFSOFolder.Size
                Else ' If the item is not a folder, then I assume it will be a file?
                'Dim ObjFSOFile As Scripting.File: Set ObjFSOFile = objFSO.GetFile(Pf & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                Dim ObjFSOFile As Object: Set ObjFSOFile = objFSO.GetFile(Pf & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                 Let MeActiveCell.Offset(Rw + 1, Clm) = ObjFSOFile.Size
                End If
             Let MeActiveCell.Offset(Rw + 2, Clm) = Format(objWSOFolder.GetDetailsOf(FldItm, 3), "dd,mmm,yy")
             Let MeActiveCell.Offset(Rw + 3, Clm) = Format(objWSOFolder.GetDetailsOf(FldItm, 4), "dd,mmm,yy")
             Let MeActiveCell.Offset(Rw + 4, Clm) = objWSOFolder.GetDetailsOf(FldItm, 166)
            '_________________________________________________________________________________________________
            ' 2b  Here we may pause the macro, whilst another copy of it is started
            If objWSOFolder.GetDetailsOf(FldItm, 2) = "Dateiordner" Then Call ReoccurringFldItmeFolderProps3(Pf & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
            '_________________________________________________________________________________________________
        '   If we did pause whilst the abobe code line set off another copy, then when that is finished we will come here and resume the paused previous copy
        Next FldItm ' ============================== Main Loop  =================================================|
     
     
     Let Reocopy = Reocopy - 1  ' We are finished at this point with this running copy of the macro. (The next code line ends it). This code line here will reduce the value used to keep track of the  copy number being run
    End Sub
    
    Last edited by DocAElstein; 01-27-2024 at 04:04 AM.

  3. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Here is the main recursion / reoccurring macro 3 corrected slightly for to get the Late Binding working correctly

    A couple of things were wrong, or rather one thing wrong, which hid a another problem that should have occurred: I had a few things not declared as objects as they should have been. As I coincidently still had the two library references checked, all still worked, and so did a string variable in this bit Set objWSOFolder = objWSO.Namespace(Pf)
    Taking the references off, revealed the problem. Once that was fixed the other problem cropped up https://stackoverflow.com/questions/...88851#77888851
    https://microsoft.public.access.nark...d-in-vba#post5


    This next coding is OK, I think

    Code:
    Option Explicit
    '  "Global" variables that must be declared here
    Dim Clm As Long, Reocopy As Long ' variable for column number to put file or folder details in, number representing the copy of the second macro running at any time
    '  Variables useful/ efficient to declare here as "Global" variables
    'Dim objWSO As Shell32.Shell                 ' Early Binding          ' Set objShell = New Shell32.Shell             '    https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg     https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
    Dim objWSO As Object                        ' Late Binding
    'Dim objFSO As Scripting.FileSystemObject    ' Early Binding          ' Set objFSO = New Scripting.FileSystemObject  ' https://i.postimg.cc/d1GHPGxJ/Microsoft-Scripting-Runtime-Library.jpg
    Dim objFSO As Object                        ' Late Binding
    Dim MeActiveCell As Range                   ' For convenience all output will be referred to a start point. The user should make a selection in the workbook window that has the worksheet for output showing in it.  We will then be able to get the ramge object into VBA from the  ActiveCell  property of that workbook window
    Sub PassFolderForReocursing3()  '
    Rem 0
     Let Clm = 1: Reocopy = 0                                         ' When this macro starts we have not started any output so our column number for output should not yet have been set, and no copies of the next macro will be running so the variable keeping track of the copy number of that macro should not have a number >= 1
    Rem 1
    Dim Ws As Worksheet: Set Ws = Me                                  ' This is and the next bits are a personal preferrence. I like to fully explicitly tell VBA where things are, and I also have a habit of putting coding intended for a worksheet in that particular worksheets code module. Many people work on whatever worksheet is active, so they may prefer to change this to   Set Ws = Application.ActiveSheet, and use that in the next bit.
    Me.Activate: Set MeActiveCell = Workbooks(Me.Parent.Name).Windows.Item(1).ActiveCell ' https://eileenslounge.com/viewtopic.php?p=313747#p313747
    ' 1b
    Dim Parf As String:  Let Parf = ThisWorkbook.Path                 ' This should be given the path to the folder where the folder of interest is, so theere is a good chance this will need to be changed to suit quit often.
    ' 1c  A short string part of the path put top left, not necerssary but just useful for later referrence to give indication of where the main folder was got from
        If Len(Parf) - Len(Replace(Parf, "\", "", 1, -1, vbBinaryCompare)) >= 2 Then ' For a longer path it may be convenient to shorten the output given to the last bit
         Let MeActiveCell = Mid(Parf, InStrRev(Parf, "\", InStrRev(Parf, "\", -1, vbBinaryCompare) - 1, vbBinaryCompare))
        Else ' For a shorter path we can give the full path
         Let MeActiveCell = Parf
        End If
    Rem 2  Windows Shell object
    ' Set objwso = New Shell32.Shell                            '    https://i.postimg.cc/Fz9zrnNm/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg     https://i.postimg.cc/sDC9S54h/Tools-Referrences-Microsoft-Shell-Controls-And-Automation.jpg
     Set objWSO = CreateObject("shell.application")
    'Dim objWSOFolder As Shell32.Folder: Set objWSOFolder = objWSO.Namespace(Parf)
    Dim objWSOFolder As Object: Set objWSOFolder = objWSO.Namespace(Parf & "")  '   & ""   https://stackoverflow.com/questions/33868233/shell-namespace-not-accepting-string-variable-but-accepting-string-itself/77888851#77888851     https://microsoft.public.access.narkive.com/Jl55mts5/problem-using-shell-namespace-method-in-vba#post5
    
    Rem 3 Movie Maker Folder Property names and Property values.
    'Dim FldItm As Shell32.FolderItem
    Dim FldItm As Object
        For Each FldItm In objWSOFolder.Items  '  We loop through all items to find the Movie Maker folder ' =======
            If FldItm.Name = "Movie Maker" Then
            Dim Rw As Long: Let Rw = 1
            ' Property   Name of file or folder
             Let MeActiveCell.Offset(Rw, 0) = objWSOFolder.GetDetailsOf("Willy", 0)
             Let MeActiveCell.Offset(Rw, Clm) = objWSOFolder.GetDetailsOf(FldItm, 0)       '   Name of folder or file  using the WSO way
            ' Property   File or folder size. I use the FSO for this to get a better precision and also because it seems to be broken for a folder item in WSO
             Let MeActiveCell.Offset(Rw + 1, 0) = objWSOFolder.GetDetailsOf("Wonka", 1)
                If objWSOFolder.GetDetailsOf(FldItm, 2) = "Dateiordner" Then                '   GetDetailsOf(FldItm, 2)   tells me the type of the WSO item
                'Set objFSO = New Scripting.FileSystemObject     ' https://i.postimg.cc/d1GHPGxJ/Microsoft-Scripting-Runtime-Library.jpg
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                'Dim objFSOFolder As Scripting.Folder: Set objFSOFolder = objFSO.GetFolder(ThisWorkbook.Path & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                Dim objFSOFolder As Object: Set objFSOFolder = objFSO.GetFolder(ThisWorkbook.Path & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                 Let MeActiveCell.Offset(Rw + 1, Clm) = objFSOFolder.Size
                Else ' If the item is not a folder, then I assume it will be a file?
                'Dim ObjFSOFile As Scripting.File: Set ObjFSOFile = objFSO.GetFile(ThisWorkbook.Path & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                Dim ObjFSOFile As Object: Set ObjFSOFile = objFSO.GetFile(ThisWorkbook.Path & "\" & objWSOFolder.GetDetailsOf(FldItm, 0))
                 Let MeActiveCell.Offset(Rw + 1, Clm) = ObjFSOFile.Size
                End If
             ' Property   Date Last Modified   Änderungsdatum
              Let MeActiveCell.Offset(Rw + 2, 0) = objWSOFolder.GetDetailsOf(42, 3)
              Let MeActiveCell.Offset(Rw + 2, Clm) = Format(objWSOFolder.GetDetailsOf(FldItm, 3), "dd,mmm,yy")
             ' Property   Date Created         Erstelldatum
              Let MeActiveCell.Offset(Rw + 3, 0) = objWSOFolder.GetDetailsOf(42, 4)
              Let MeActiveCell.Offset(Rw + 3, Clm) = Format(objWSOFolder.GetDetailsOf(FldItm, 4), "dd,mmm,yy")
             ' Property   Version
              Let MeActiveCell.Offset(Rw + 4, Clm) = objWSOFolder.GetDetailsOf(666, 166)
              Let MeActiveCell.Offset(Rw + 4, Clm) = objWSOFolder.GetDetailsOf(FldItm, 166)
             Rem 4
             Let Clm = 0
             MeActiveCell.Offset(0, 2).Select: Set MeActiveCell = Workbooks(Me.Parent.Name).Windows.Item(1).ActiveCell ' https://eileenslounge.com/viewtopic.php?p=313747#p313747
             ' 4b
             Call ReoccurringFldItmeFolderProps3(Parf & "\Movie Maker")
             Exit For ' Once we have passed on the full path of the folder,  Movie Maker  , then we are finished with this macro, so we don't need loop further looking fot the Movie Maker folder
            Else
            End If
        Next FldItm ' ===========================================================================================
    End Sub
    Recursion / Reoccring part in next post
    Last edited by DocAElstein; 01-27-2024 at 01:37 PM.

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Later
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  5. #5
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Some stuff to save for prosperity, related to this main forum post https://eileenslounge.com/viewtopic....315229#p315229
    https://eileenslounge.com/viewtopic....315235#p315235


    Some Microsoft documentation as of March 2024, here: https://learn.microsoft.com/en-us/of...rror-statement ( Just some of the first bits, relevant to the discussion at https://eileenslounge.com/viewtopic.php?f=30&t=40752 )


    On Error statement Article 03/30/2022

    Syntax
    On Error GoTo line
    On Error Resume Next
    On Error GoTo 0


    The On Error statement syntax can have any of the following forms:

    Statement Description
    On Error GoTo line Enables the error-handling routine that starts at line specified in the required line argument.
    The line argument is any line label or line number.
    If a run-time error occurs, control branches to line, making the error handler active.
    The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.
    On Error Resume Next Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred and execution continues. Use this form rather than On Error GoTo when accessing objects.
    On Error GoTo 0 Disables any enabled error handler in the current procedure.

    Remarks
    If you don't use an On Error statement, any run-time error that occurs is fatal; that is, an error message is displayed and execution stops.

    An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error. Control returns to the calling procedure.

    If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no inactive, enabled error handler is found, the error is fatal at the point at which it actually occurred.

    Each time the error handler passes control back to a calling procedure, that procedure becomes the current procedure. After an error is handled by an error handler in any procedure, execution resumes in the current procedure at the point designated by the Resume statement. .........
    ........................
    Last edited by DocAElstein; 03-16-2024 at 02:04 PM.

  6. #6
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,408
    Rep Power
    10
    Some extra notes for these main forum posts
    https://www.excelfox.com/forum/showt...ll=1#post24163
    https://www.excelfox.com/forum/showt...age3#post24163
    https://eileenslounge.com/viewtopic....317547#p317547
    https://eileenslounge.com/viewtopic....317533#p317533


    This is the original coding from SamPi , which confused me a bit for a few reasons
    The choice of variable names;
    the use of a .xlam file; ( and
    the Class module is only part of the story
    )


    Class Module:
    Code:
    Option Explicit
     
    Public WithEvents App As Application
     
    Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
    Dim s As String
    
    s = Wb.Name
    
    If s = "test.csv" Then MyMacro
    
    End Sub
    
    Sub MyMacro()
    MsgBox "Yes"
    End Sub
    
    ThisWorkbook:
    Code:
    Option Explicit
    
    Dim App             As New App
     
    Private Sub Workbook_Open()
         
       Set App.App = Application
    
    End Sub
    
    Attached Files Attached Files
    Last edited by DocAElstein; 05-22-2024 at 10:07 PM.

Similar Threads

  1. VBA to Reply All To Latest Email Thread
    By pkearney10 in forum Outlook Help
    Replies: 11
    Last Post: 12-22-2020, 11:15 PM
  2. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  3. Replies: 19
    Last Post: 04-20-2019, 02:38 PM
  4. Search List of my codes
    By PcMax in forum Excel Help
    Replies: 6
    Last Post: 08-03-2014, 08:38 AM

Posting Permissions

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