List excel files with embedded objects inside

MarcMermans

New Member
Joined
Dec 4, 2012
Messages
7
Hello,

Is it possible to do a seach in a lot of excel files (>500) to find the excel files wich have an embedded objects inside.
If so how can I do this with VBA ?


Best regards.

Marc
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
try this.
the code will let you select folder where your excel files are located and the code will loop through all files and return you the count of msoLinkedOLEObject in each excel workbook in folder.

i think this is what you want.
all the best.

Public Function ShowFolderList()
'Reference it to MS Form x.x object lib

Dim wb As Workbook
Dim i As Shape
Dim fld As String
Dim fs, f, f1, fc
Dim objcount As Integer
objcount = 0

fld = FolderSelect()
If Len(fld) < 3 Then Exit Function

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fld)
Set fc = f.Files

For Each f1 In fc
If f1 Like "*.*xls*" Then
Set wb = Workbooks.Open(Filename:=fld & "\" & f1.Name)

wb.Activate
For Each i In ActiveSheet.Shapes
If i.Type = msoLinkedOLEObject Then
Debug.Print i.Name
objcount = objcount + 1
End If
Next
If objcount > 0 Then MsgBox "Workbook " & wb.Name & " has " & objcount & " msoLinkedOLEObject."
wb.Close
Set wb = Nothing

End If
Next
End Function


Public Function FolderSelect() As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim vrtSelectedItem As Variant
With fd
.AllowMultiSelect = False
If .Show = -1 Then
FolderSelect = .SelectedItems(1)
Else
End If
End With
Set fd = Nothing
End Function
 

MarcMermans

New Member
Joined
Dec 4, 2012
Messages
7
Pedie,

Thanks for your solution, it works fine. Now I have to add a logging part so that after checking the files a get an overview of the files wich have embedded objects inside.

Best Regards,

Marc
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
try this code.
it will list files names and objects count.


the code is not Tested but should work :)
Code:
Code:
[FONT=courier new]Option Explicit
Public Function ShowFolderList()[/FONT]
[FONT=courier new]Dim wb As Workbook
Dim i As Shape
Dim fld As String
Dim fs, f, f1, fc
Dim objcount As Integer
Dim wb1 As Workbook[/FONT]
[FONT=courier new]
Set wb1 = Workbooks.Add
wb1.Sheets(1).Range("A1").Value = "Workbook Names"
wb1.Sheets(1).Range("B1").Value = "msoLinkedOLEObject Count"
Cells.EntireColumn.AutoFit[/FONT]
[FONT=courier new]objcount = 0[/FONT]
[FONT=courier new]fld = FolderSelect()
If Len(fld) < 3 Then Exit Function
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fld)
Set fc = f.Files[/FONT]
[FONT=courier new]   For Each f1 In fc
        If f1 Like "*.*xls*" Then
        Set wb = Workbooks.Open(Filename:=fld & "\" & f1.Name)
        
            wb.Activate
            For Each i In ActiveSheet.Shapes
                If i.Type = msoLinkedOLEObject Then
                    objcount = objcount + 1
                End If
            Next
            
                If objcount > 0 Then
                    wb1.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = wb.Name
                    wb1.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = objcount
                End If
                
            wb.Close
            Set wb = Nothing
        End If
    Next
wb1.activate
msgbox "Completed!"

End Function
Public Function FolderSelect() As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim vrtSelectedItem As Variant
With fd
.AllowMultiSelect = False
If .Show = -1 Then
FolderSelect = .SelectedItems(1)
Else
End If
End With
Set fd = Nothing
End Function[/FONT]
 

Forum statistics

Threads
1,082,017
Messages
5,362,695
Members
400,686
Latest member
Aakash

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top