Auto save as text and close in code?

G

GD

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!!
 
L

Luke M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top