cleaning

iknowu99

Well-known Member
Joined
Dec 26, 2004
Messages
1,158
i have an excel workbook called "organize_Macros.xls"
the goal is to look through all accessible xls files in specific directory and erase vba that they have. << this part seems to work except for two plus a half problems.

one problem is sometimes when openin workbooks there is a warning question: update links or not. even after unclicking the options checkmarks to update links. possible because error two

problem two is it's an actual pop up box askin about updating links

the half the problem is probably because of the prior two: excel freezes up!

some excel sheets to be cleaned are password protected. these workbooks should be saved to a new location.

also a log of read_only files would be great, this way i can manually look at them

<code>
Code:
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
        (ByVal ClassName As String, ByVal WindowName As String) As Long
    
    Private Declare Function LockWindowUpdate Lib "user32" _
        (ByVal hWndLock As Long) As Long


    Sub EliminateScreenFlicker()
        Dim VBEHwnd As Long
        
        Application.VBE.MainWindow.Visible = False

        'Application Ready
     Application.ScreenUpdating = False
     Application.EnableEvents = False
     
    Application.DisplayAlerts = False
    
On Error Resume Next
    Dim IFoundFiles As Integer
    Dim Pos As String, file As String, path As String
    Dim wbSource, n
    Dim VBCodeMod
Dim VBComps
Dim VBComp
Dim vbext_ct_StdModule, vbext_ct_MSForm, vbext_ct_ClassModule
    
    
    'Start FileSearch
    With Application.FileSearch
        .LookIn = "G:\"
        .Filename = "*" & ".xls"
        .FileType = msoFileTypeExcelWorkbooks
        .SearchSubFolders = True
        .Execute
        If .Execute > 0 Then
        
            'loop through all found files
            For IFoundFiles = 1 To .FoundFiles.Count
                'set incidental variables
                Pos = InStrRev(.FoundFiles(IFoundFiles), "\")
                file = Right(.FoundFiles(IFoundFiles), Len(.FoundFiles(IFoundFiles)) - Pos)
                path = Left(.FoundFiles(IFoundFiles), Pos)

                 Workbooks.Open Filename:=Workbooks.Open(path & file), UpdateLinks:=xlUpdateLinksNever
                 Set wbSource = ActiveWorkbook

If wbSource.ReadOnly Then
    wbSource.Close False
Else

Set VBComps = wbSource.VBProject.VBComponents
For Each VBComp In VBComps
   Select Case VBComp.Type
      Case vbext_ct_StdModule, vbext_ct_MSForm, _
            vbext_ct_ClassModule
         VBComps.Remove VBComp
      Case Else
         With VBComp.CodeModule
            .DeleteLines 1, .CountOfLines
         End With
   End Select
Next VBComp
                    wbSource.Close True
End If
'Skip:
            Next IFoundFiles
            
        End If
            
    End With
      
    End Sub
</code>
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top