Option Explicit causing compile error

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
This code is periodically crashing excel when a user doesn't save a workbook.

Code:
Sub FillLog(uName)
Option Explicit
uName = Environ("UserName")


Sheets("Values").Cells(10, 43) = uName


End Sub

I ran the "Compile VBA Project" from the debug menu and it gave me an error or "invalid inside procedure" so I figured I messed up and needed to add the Option Explicit above the sub FillLog(uName)...The problem is, that it is in hundreds of workbooks :( Any advice on how to fix this?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
try this:

Code:
Option Explicit


Sub FillLog(uName)
    uName = Environ("UserName")
    Sheets("Values").Cells(10, 43) = uName
End Sub


Sub test()
    Dim uName As String
    Call FillLog(uName)
End Sub
 
Last edited:
Upvote 0
Solution
Is there a way to write a macro to delete a specific macro upon workbook opening that can be saved in a personal macro workbook?
 
Upvote 0
Is there a way to write a macro to delete a specific macro upon workbook opening that can be saved in a personal macro workbook?

To remove a module:

Code:
Sub Remove_Module()
    Workbooks("other.xlsm").VBProject.VBComponents.Remove Workbooks("other.xlsm").VBProject.VBComponents("Module1")
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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