Question : Generic path to open a file from VBA

Hi EE,

I have a code that opens two files. Both the excel file and the files to be opened are placed in the desktop. Now I use the instruction ChDir to set the Desktop folder the place where VBA must go to open both files.

But this vba code must be used in several pc's, and in every pc the desktop path is different due to different user names.

I would like to now if it's possible to write a "generic" path for the vba to find the files with no matter of which pc is runned. The files will be placed always in the desktop folder.

Thanks,

Martí.

Answer : Generic path to open a file from VBA

Here's another way to get the Desktop path.....

Sub YourMacro()
    Dim WSHShell As Object
    Set WSHShell = CreateObject("Wscript.Shell")
    ChDir WSHShell.SpecialFolders("Desktop")

    'THE REST OF YOUR CODE

    Set WSHShell = Nothing
End Sub

Regards,

Wayne
Random Solutions  
 
programming4us programming4us