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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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