Question

Locked

File referencing in vba

By simon.c.l ·
Hi All. I have a user form in Word that populates a doc, saves as a temp file, emails as attachment and then kills the temp file. I am worried that with momre than one user at any one time one person's code might kill another person's temp file before they have sent it. Any ideas as to how I might create a unique filename each time or other suggestions would be most helpful.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Append users login name

by Slayer_ In reply to File referencing in vba

You can append the users login name, or the computers name to the file name, heck even the creation time would work.
You can also have your code figure out which files already exist and increment to a new one each time, so if
File1 exists,
check file2
if file2 exists
check file3
if file3 does not exist
create it.

But your better off appending user names. User names are in an environment variable.

sString = vba.environ("USERNAME")

sString will contain the currenlty logged in users name. I may have got the function call wrong, check it in the context menus as you type it in.


So you could say

Dim iFile as integer
iFile=freefile
open "C:\file_" & vba.environ("USERNAME") & ".txt" for output as #iFile

Collapse -

Brill. This works fine.

by simon.c.l In reply to Append users login name

Thank you.

Collapse -

No problem

by Slayer_ In reply to Brill. This works fine.

I'm sitting here waiting for a giant SQL script to finish running, so happy to help.


PS. Be sure to make helpful responses as helpful so other people get a good idea that the question was answered. :)

Back to Software Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums