Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Help with text file deletion

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rhamre@citation.com - 19 Oct 2005 23:13 GMT
Currently i have a macro that will run any number of other macros on all the
files in any number of folders.

Now, i have the user input how many macros to run, and how many folders.

For the amount of macros and folders, i have the user input the folder paths
and the macro names.

The paths and names are exported to a text file on a network drive that i
created for these types of output cases where i need to store and retrieve
information.

Well, the company that i work with wants to make my macros a company wide
deal. The problem i ran into is that if people run the same macro at the same
time, the log file person a is using, get's deleted when person b tries to
use it.

Following is a part of my code...

This part i use to create the files...

   Set f = CreateObject("Scripting.FileSystemObject")
   Set tLog = f.Createtextfile("Y:\ryan\vb\folderlist.txt", True)
   Set mLog = f.Createtextfile("Y:\ryan\vb\macrolist.txt", True)

Here is part of my code that gets the inputs and writes it to the file

   nfolders = InputBox(prompt:="How many folders do you want to run macro
on?")
   
   If Len(nfolders) = 0 Then Exit Sub
   
   Application.ScreenRefresh
   
   For y = 1 To nfolders
   
       If nfolders = 1 Then
           path = InputBox(prompt:="Input the folder's path.")
       ElseIf y = nfolders Then
           path = InputBox(prompt:="Input the last folder's path.")
       ElseIf y = 1 Then
           path = InputBox(prompt:="Input the 1st folder's path.")
       ElseIf y = 2 Then
           path = InputBox(prompt:="Input the 2nd folder's path.")
       ElseIf y = 3 Then
           path = InputBox(prompt:="Input the 3rd folder's path.")
       Else
           path = InputBox(prompt:="Input the " & y & "th folder's path.")
       End If
       
       If Len(path) = 0 Then
           MsgBox ("You hit cancel or didn't put anything in.")
           Exit Sub
       End If
       
       tLog.writeline (path)
       
       Application.ScreenRefresh
       
   Next y
   
   tLog.Close

after all this i do...

   tLog = "Y:\ryan\vb\folderlist.txt"

   Open tLog For Input As #1

   Do While Not EOF(1)

Now, to solve this i'm going to change the program to create the txt file at
C:\ and then what i want it to do is erase it when the program is
finished.... how can i do this?
Jezebel - 20 Oct 2005 00:31 GMT
Make the file names variable and guaranteed unique. You can also store the
file in the each user's own APPDATA folder, which you can retrieve using:
environ$("APPDATA")

eg
Dim pFileName as string

pFileName = environ$("APPDATA") & "\folders" & format$(now, "yymmddhhnnss")
& ".txt"
Set tLog = f.Createtextfile(pFileName,True)

f.Deletefile pFileName

BTW, you don't need the FileSystemObject for any of this.
Open/Print/Input/Kill all work perfectly well.

> Currently i have a macro that will run any number of other macros on all
> the
[quoted text clipped - 74 lines]
> C:\ and then what i want it to do is erase it when the program is
> finished.... how can i do this?
rhamre@citation.com - 20 Oct 2005 02:16 GMT
Thank you very much for this, this is the answer i needed.

BTW, i don't know VB, so that's most likely why the programming is so
shoddy. ;-)

> Make the file names variable and guaranteed unique. You can also store the
> file in the each user's own APPDATA folder, which you can retrieve using:
[quoted text clipped - 90 lines]
> > C:\ and then what i want it to do is erase it when the program is
> > finished.... how can i do this?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.