Code suddenly doesn't work anymore

Guus2005

AWF VIP
Local time
Today, 03:31
Joined
Jun 26, 2007
Messages
2,642
I have this code to open a file with the default application based on the extension.
It is usually used for a .txt extension and it opened Notepad++.
Code:
Public Sub openScriptInDefaultEditor(strFilename As String)
    'File is opened in default editor

    Dim strFullPath As String
    Dim fso As Object
    Set fso = CreateObject("Shell.Application")
    
    strFullPath = Nz(DLookup("Pad", "tblScript", "Projectnaam = '" & TempVars!Projectnaam & "' and Scriptnaam = '" & strFilename& "'"), "")
    
    If Len(strFullPath) > 0 Then
        If FileExist(strFullPath) Then
            fso.Open strFullPath
        Else
            MsgBox "File not found at location:" & vbCrLf & strFullPath, vbExclamation, "Oops"
        End If
    Else
        MsgBox "Path is empty, no file found", vbExclamation, "???"
    End If

End Sub

It stopped working and i don't know why??

If anyone can tell me what's wrong with the code which i didn't change, why it stopped working or if you have an alternative, please let me know!

Thanks for your time.
 
I suggest that you replace the concatenated path "strFullPath" with a hard-coded path so you know exactly where the code is looking for the file, Here:-

If FileExist(strFullPath) Then

And report back the result...
 
I got a working path when i look at the contents of the strFullPath variable.

?strFullPath
c:\Temp\Scripts\Slablaadje.txt

When i open notepad++ en open a file and paste in the path, it opens nicely.

The code worked for a few months, and now it doesn't.
Code:
fso.Open "c:\Temp\Scripts\Slablaadje.txt"
Doesn't give me anything. Not even an errorcode.

EDIT: Forgot to mention: Sometimes decompiling fixes the problem by showing where there is an issue. (which you didn't find in the compiled version). But that didn't do anything for me.
 
Last edited:
There was a windoze update in the last few days?
Possible Coincidence?
 
maybe you have associated a .txt file with a different default app, somehow. Would that cause this issue?
 
Hi. Just had to ask, since we can't see what you're seeing. Doesn't work means nothing happens or you get an error?
 
If a text file was associated with e.g. UltraEdit, UltraEdit would be used to open the text file.
Ofcourse i rebooted (a few times by now) and even reinstalled the Notepad++ app which i normally use for text files.

Looks like im the only one ever to come accros this kind of problem. Shoot.

When i am debugging and put a breakpoint on the fso..Open line (with a single dot), F8 brings me neatly to the next line to be executed.
As if the line didn't exist.

I am at a loss.
Is there another way to open a text file using the default app?
 
If a text file was associated with e.g. UltraEdit, UltraEdit would be used to open the text file.
Ofcourse i rebooted (a few times by now) and even reinstalled the Notepad++ app which i normally use for text files.

Looks like im the only one ever to come accros this kind of problem. Shoot.

When i am debugging and put a breakpoint on the fso..Open line (with a single dot), F8 brings me neatly to the next line to be executed.
As if the line didn't exist.

I am at a loss.
Is there another way to open a text file using the default app?
Have you tried ShellExecute?
 
guus,

have you tried the actual "file system object" that is part of VBA? i believe the method is called "openTextfile". that's not the fso you had declared. you declared the dos shell, right?
 
furthermore, another method is to just use DOS directly to open it by running a command in the invisible command line through VBA
 

Users who are viewing this thread

Back
Top Bottom