How write Macro to save a .xml and a .txt version of a file

B

Barry

Hi,
I need to automate the process of producing TWO versions of some data.
Firstly a .xml version - which I have formatted on a sheet called 'data.xml'
and secondly, a .txt version - which I have formatted on a separate sheet
called 'data.htm'.

The first time it runs .... seemingly all is OK,
but subsequently, the output files ALREADY EXIST,
so I wrapped the code with Application.DisplayAlerts = False (then True),
but still having problems - sometimes the 1st file gets written, sometimes
neither.

Can someone tell me what's wrong with my syntax/logic
and/or suggest a better way - thanks (note - it has to work on all
version sof XL 2000 + )

Sub Macro1()
'
' Macro1 Macro
'
ActiveWorkbook.Save
MsgBox "Note: The current Spreadsheet has been automatically saved .. as
the name will now be changed by the program."
'

Application.DisplayAlerts = False
'
Sheets("data.xml").Select
Cells.Select
ActiveWorkbook.SaveAs Filename:= _
"meter_data.xml" _
, FileFormat:=xlUnicodeText, CreateBackup:=False
'
Sheets("data.html").Select
ActiveWorkbook.SaveAs Filename:= _
"C:meter_data.txt", _
FileFormat:=xlUnicodeText, CreateBackup:=False
'
Application.DisplayAlerts = True
'
MsgBox "Note: Both files have now been saved to the current
subdirectory. The Spreadsheet MUST now be closed without saving ... as the
name has been changed by the program"
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