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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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