I can define Log to be a subroutine in project Personal.xlsb and use it within that project, but not outside it.

DSlomer64

New Member
Joined
Mar 31, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Let me start by saying that I know that Log is the natural logarithm function and that I used the word Log as the name of a subroutine, without thinking. But it caused no problem initially.

In project Personal.xlsb, if I define Log as follows in module IO, I can use Log in a different module within the project:

VBA Code:
Public Sub Log(filenumber, msg)
On Error GoTo skippy
    Print #filenumber, msg
skippy:
    Debug.Print msg
    MsgBox msg
End Sub

Here I use Log successfully in module Backup within the same project:

VBA Code:
 n = FreeFile()
    Open outputFile For Output As #n
         Log n, "Backing up these projects (to..." & staticBackupFolder & newBackupSubFolder & ")"

But if I use similar code in external project Blood.xlsm, the compiler highlights Log and gives the compiler error below:

VBA Code:
         Log 0, "Wrote new values to " & STATE_FILE"
       
                Wrong number of arguments or invalid property assignment

Of course, the error is because the compiler isn't using the definition in module IO where I successfully redefined Log in project Personal.xlsb. It thinks Log is the natural logarithm function.
(I confirmed this by changing the statement with the error to msgbox Log(Exp(246)) and getting 246 as expected.)(Log and Exp are inverse functions, which "cancel" each other.)

I could simply change all instances of Log to Logg or Logit or Stump, etc. and be on my way. Or I could copy the code into project Blood.xlsm.

But the question is much deeper, as a similar situation isn't difficult to imagine. The compiler allowed use of the redefinition of Log in module Backup that is internal to Personal.xlsb, so surely there's a way to extend the scope of Log to external projects. I would call any attempted usage of Log an unresolved external reference for any attempted usage outside the project where it's defined.

So here's my question:

What declaration or option or hunk of code or ...(?)... will permit me to use Log as a subroutine accessible from any project external to (outside of) Personal.xlsb?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try using Application.Run, as in:

VBA Code:
     Application.Run "PERSONAL.XLSB!Log", 0, "Wrote new values to " & STATE_FILE

But it is bad programming practice to name subroutines and functions using names already used by internal functions.
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,827
Members
449,051
Latest member
excelquestion515

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