Error message in logfile code

mwperkins

Board Regular
Joined
Oct 29, 2002
Messages
156
The following code works fine on my PC (Excel 2000, Win NT Pro), and most of the users I've tested this with, but some people get a "compile error in hidden module".

Code:
Option Explicit
Sub test5()
    Dim f As Integer
    Dim LogFile As String
    Dim TempStr1, TempStr2, TempStr3, TempStr4, TempStr5, TempStr6, TempStr7
    
    Err.Clear
    On Error Resume Next
    TempStr1 = Format(Date, "yyyy mm")
    
    LogFile = "\\Gbtdc036\UKNMSC\PPI\PPI Workbook 2003\S - Standards & Procedures\3point BottomUp Estimating\"
    LogFile = LogFile & TempStr1
    LogFile = LogFile & "3pointTool usage log.csv"
    TempStr1 = Format(Now, "yyyy-mm-dd hh:mm:ss")
    TempStr2 = Application.UserName
    TempStr3 = "B"
    TempStr4 = "C"
    TempStr5 = ThisWorkbook.FullName
    TempStr6 = "0.b Tests"
    TempStr7 = "Opened"

    f = FreeFile
    Open LogFile For Append As #f
    Write #f, TempStr1, TempStr2, TempStr3, TempStr4, TempStr5, TempStr6, TempStr7
    Close #f

    If Err.Number <> 0 Then
        Worksheets("sheet1").Range("B8").Value = "Failed log test - Error:" & Err.Number
    Else
        Worksheets("sheet1").Range("B8").Value = "Passed log test"
    End If
    Err.Clear
End Sub

I've sent a copy of the above code to affected users with the VBA project unlocked and I am led to believe that the error message is "Cannot find project or library".

I know that some users will have problems connecting to the specified location and was hoping that "On error resume next" would mean that they don't get an error.

To be honest, I don't really understand the "f = FreeFile" - "Close #f" lines - I adapted copied and adapted them from somewhere else.

Can anyone suggest bullet-proof amendments to the code that will help it run safely on Win98, WinXP, WinNT and Excel 97 and 2000?


Thanks,
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I don't beleive it is this code that is causing you grief......
There maybe some other Reference that is missing that you may
inadvertently set....that they do not have on there machines..

Your Users may need to check their references...

Your code is OK as it is to Run on Given machines.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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