Code question - problems including windows login as variable in file name

Broker666

Registered User.
Local time
Today, 06:19
Joined
Dec 13, 2012
Messages
26
Hi,

I'm trying to delete a file that uses the user's windows login id as a variable in the file name but am having a little trouble. I think I'm nearly there... I've assigned the windows login ID to the string User_FX with a function and have written the following code, but it returns an error message stating that there are invalid property property assignments or a wrong number of arguments. I'm sure this is obvious to the more educated but I have tried numerous permutations to no avail.

Sub Killfilewithuservariable()

If FileFolderExists("C:\Options\G_Reports\G_Reports_" & User_FX, ,".xlsx") Then

Kill "C:\Options\G_Reports\G_Reports_" & User_FX, ,".xlsx"

Else

End If

End sub

Any help would be much appreciated.

B666.
 
I believe you need

"C:\Options\G_Reports\G_Reports_" & User_FX & ".xlsx"
 
Hi Bob,

Thanks for getting back to me, it seems to like to code but cannot find the file? I have returned the User_FX variable to a msgbox and it is 'Administrator' and the file is saved as C:\Options\G_Reports\G_Reports_Administrator.xlsx so i'm not sure what the issue is, any ideas?
 
Hi Bob,

Thanks for getting back to me, it seems to like to code but cannot find the file? I have returned the User_FX variable to a msgbox and it is 'Administrator' and the file is saved as C:\Options\G_Reports\G_Reports_Administrator.xlsx so i'm not sure what the issue is, any ideas?
Change this part:
If FileFolderExists("C:\Options\G_Reports\G_Reports_" & User_FX & ".xlsx") Then


to this instead

If Dir("C:\Options\G_Reports\G_Reports_" & User_FX & ".xlsx") <> vbNullString Then
 
Works like a dream, thanks Bob. Hopefully one day I will be able to offer to same sort of good advice I always receive on this forum.

Regards,

B.
 

Users who are viewing this thread

Back
Top Bottom