Modify existing Macro to create new txt file and close the file

btamulis

New Member
Joined
Mar 17, 2010
Messages
17
I have a macro which works fine but needs final touch...........

at end of macro I need to do two things:

1. Copy the existing workbook as a tab delimited (txt) workbook in a different folder with a different file name.
2. Save the existing workbook (xls) in the current file path - simply overwriting the 'old' file.....end user shouldn't get any prompts - excel simply....closes

Any thoughts?

thank you in advance.......
 

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.
Re: Modify existing Macro to create new txt file and close the file..............

Hi

how about

Code:
Sub CloseBook()
    'turn off alerts
    Application.DisplayAlerts = False
    
    'if unsaved changes present save Workbook
    If ThisWorkbook.Saved = False Then
        ThisWorkbook.Save
    End If
    
    'Now save file as .TXT
    myFileName = "C:\TEMP\Excel test file.txt"
    
    ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlCurrentPlatformText
       
    'close Excel
    Application.Quit
    
End Sub

obviously you would need to change the setting of 'myFileName' to what ever folder/file name you need
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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