1 file output to 2 separate folders?

LwarenceD

New Member
Joined
Nov 24, 2005
Messages
29
Greetings Again,

I am trying to streamline a bit more of my project.

What I am trying to do is to append 2 separate text files into a 3rd.

that 3rd file needs to be saved in 2 separate locations (Archived file and a user file)

So far I have been able to Append, and save to a single location but I cannot make it save to a second location after the first.

Code:
' looks for the operator selected file to append.
'
    ChDir "C:\Dig\data\"
    sFilename = Application.GetOpenFilename("Text Files (*.txt), *.txt")

' Recreates the user file to ensure its always blanks to start with
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set u = fs.CreateTextFile("H:\Dig\userfile.txt", True)
    u.WriteLine ("")
    u.Close
'
' opens the blank file, then appends the operator selected file and the static file
  
  Open "H:\Dig\userfile.txt" For Append As #1   'Open the file to be created
  Open sFilename For Input As #2  'Open the file to be appended to
  Open "C:\Dig\messages\get1.txt" For Input As #3  'Open the file to be appended
  Print #1, Input(LOF(2), 2);           'Read in the second file appending it to the first
  Print #1, Input(LOF(3), 3);           'Read in the third file appending it to the first
  Close 1, 2, 3                        'Close all files
End Sub


Now the H drive is a USB Jump Drive the user is supposed to insert before running the workbook.

I've had a few instances where the user forgot and it crashes. What would the simplest error handling be for this? Is there a small routine to confirm the existance of the H drive or ask the user to connect if its not there?

Now with the same event I need to be able to create an exact duplicate of the H:\Dig\userfile.txt in the C:\Dig\Archived\ directory.

Should I just replicate the code and change the output to the archived folder? or is there a quicker way to send the userfile.txt file to 2 separate folders at the same time?

Cheers
Lwrence
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I think this is what you want :-
Code:
Sub test()
    On Error GoTo NoDrive
    ChDrive "H"     ' try to change drive
    On Error GoTo 0 ' allow another error message
    FileCopy "H:\Dig\userfile.txt", "C:\Dig\Archived\userfile.txt"
    Exit Sub
NoDrive:
    MsgBox ("Drive H not available")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top