ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Auto save as text and close in code? (https://www.excelbanter.com/new-users-excel/231194-auto-save-text-close-code.html)

GD

Auto save as text and close in code?
 
Upon opening C:\Download\PBDB\CMDM.xls, I need to automatically save it as a
..txt file in the same folder, and then close it. Can someone help me with
the code I'd need for that?

Thanks!!
--
GD

Luke M

Auto save as text and close in code?
 
Assuming workbook is a single worksheet (you can't save multiple sheets in a
text file)

Open the VBA editor, go to the ThisWorkbook module, and paste this in. Do
note that this arrangement could be very annoying to anyone trying to open
the workbook for editing.

Private Sub Workbook_Open()
ThisWorkbook.SaveAs Filename:= _
"C:\Download\PBDB\CMDM.txt", FileFormat:= _
xlUnicodeText, CreateBackup:=False
Application.DisplayAlerts = False
ThisWorkbook.Close
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"GD" wrote:

Upon opening C:\Download\PBDB\CMDM.xls, I need to automatically save it as a
.txt file in the same folder, and then close it. Can someone help me with
the code I'd need for that?

Thanks!!
--
GD


GD

Auto save as text and close in code?
 
Awesome! Thanks, Luke!

P.S. I'm the only one who will need this file, so no worries.
--
GD


"Luke M" wrote:

Assuming workbook is a single worksheet (you can't save multiple sheets in a
text file)

Open the VBA editor, go to the ThisWorkbook module, and paste this in. Do
note that this arrangement could be very annoying to anyone trying to open
the workbook for editing.

Private Sub Workbook_Open()
ThisWorkbook.SaveAs Filename:= _
"C:\Download\PBDB\CMDM.txt", FileFormat:= _
xlUnicodeText, CreateBackup:=False
Application.DisplayAlerts = False
ThisWorkbook.Close
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"GD" wrote:

Upon opening C:\Download\PBDB\CMDM.xls, I need to automatically save it as a
.txt file in the same folder, and then close it. Can someone help me with
the code I'd need for that?

Thanks!!
--
GD



All times are GMT +1. The time now is 09:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com