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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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