Remove a virus module without opening excel file or enabling macro

gifariz

Board Regular
Joined
May 2, 2021
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hi, all. I have problem with virus in a form of excel VBA module spreading in our office. Particularly the virus name is "results", if anyone has ever know.
This virus module creates an excel file in deep C drive folder and keep creating new virus modules in all excel file that we open and save them as macro-enabled files.
I know how to remove the virus, by removing the virus module from the infected excel file, and delete the virus source in deep C drive folder manually.
But the problem is, whenever another infected file opened and macro is enabled, it will spread the virus again.

I know the macro for opening an excel file, and for removing a module (looks like below, not tested), but the virus will spread again if the infected file is opened and macro is enabled.
VBA Code:
Sub RemoveMacroIfExists()
    Dim MyFileName
    Dim MyPathName
    Dim MyModuleName As String
    Dim MyModule As Object
    
    'Below will be updated to be iterative
    PathName = Range("A2").Value
    Filename = Range("A1").Value
    MyModuleName = "results"
    
    Workbooks.Open Filename:=MyPathName & MyFileName
    Workbooks(MyFileName).Activate
    
    On Error Resume Next
    Set MyModule = ActiveWorkbook.VBProject.VBComponents(MyModuleName).CodeModule
    If Err.Number = 0 Then
        ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents(MyModuleName)
    End If
    On Error GoTo 0
    
End Sub
So, I want to make a macro to check all xlsm files in our computer whether it contains a certain module and remove the module if found, without opening the excel file or without enabling the macro on that file.
Is that possible?

I want to make this macro because other employees just don't know anything about macro. So I cannot tell them how to remove the virus module & source manually and prevent future infection.
Thank you for reading and thank you in advance.
 
Please respond back once you try it to let us know if it did indeed solve your issue.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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