Save excel file as another format file

Discussion in 'Microsoft Excel Programming' started by Guest, Jul 8, 2005.

  1. Guest

    Guest Guest

    Dear,

    I run the following codes, but I can not save the file, and get an error
    message. Why?

    Dim xlExcelbook As Excel.Workbook
    ....
    xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS

    Err.Number : 1004
    Err.Description: Application-defined or object-defined error

    I have tested some file format.

    They are OK.
    xlExcelBook.SaveAs "C:\test.xls"
    xlExcelBook.SaveAs "C:\test.htm", xlHtml
    xlExcelBook.SaveAs "C:\test.csv", xlCSV
    xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText

    They can not work, and get an error message.
    xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    xlExcelBook.SaveAs "C:\test.txt", xlTextWindows

    Thanks advance!
    Liu jianzhong
     
    Guest, Jul 8, 2005
    #1
    1. Advertisements

  2. What version of excel are you using?

    If you go into the VBE and hit F2 to see the object browser and search for
    "fileformat", do you see your format constants on that list.

    (I'm wondering if some of the constants changed from one version to the
    next--and you're using the newer constant.)

    ps. your snippet of code worked ok for me in xl2003.



    ExcelReport wrote:
    >
    > Dear,
    >
    > I run the following codes, but I can not save the file, and get an error
    > message. Why?
    >
    > Dim xlExcelbook As Excel.Workbook
    > ...
    > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    >
    > Err.Number : 1004
    > Err.Description: Application-defined or object-defined error
    >
    > I have tested some file format.
    >
    > They are OK.
    > xlExcelBook.SaveAs "C:\test.xls"
    > xlExcelBook.SaveAs "C:\test.htm", xlHtml
    > xlExcelBook.SaveAs "C:\test.csv", xlCSV
    > xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText
    >
    > They can not work, and get an error message.
    > xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    > xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    > xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    > xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > xlExcelBook.SaveAs "C:\test.txt", xlTextWindows
    >
    > Thanks advance!
    > Liu jianzhong


    --

    Dave Peterson
     
    Dave Peterson, Jul 8, 2005
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Dave Peterson,

    My excel is Excel 2003. I follow your instruction, and get the constants:
    (They are OK)
    xlWorkbookNormal -4143
    xlHtml 44
    xlWebArchive 45
    xlXMLSpreadsheet 46
    xlCSV 6
    xlCurrentPlatformText -4158
    xlUnicodeText 42
    xlTextPrinter 36

    (They can not work)
    xlCSVMac 22
    xlCSVMSDOS 24
    xlCSVWindows 23
    xlTextMac 19
    xlTextMSDOS 21
    xlTextWindows 20

    I write the source code as follows:
    ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS
    or
    ActiveWorkbook.SaveAs "C:\test.txt", 21

    Best regards!
    Liu Jianzhong

    "Dave Peterson" wrote:

    > What version of excel are you using?
    >
    > If you go into the VBE and hit F2 to see the object browser and search for
    > "fileformat", do you see your format constants on that list.
    >
    > (I'm wondering if some of the constants changed from one version to the
    > next--and you're using the newer constant.)
    >
    > ps. your snippet of code worked ok for me in xl2003.
    >
    >
    >
    > ExcelReport wrote:
    > >
    > > Dear,
    > >
    > > I run the following codes, but I can not save the file, and get an error
    > > message. Why?
    > >
    > > Dim xlExcelbook As Excel.Workbook
    > > ...
    > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > >
    > > Err.Number : 1004
    > > Err.Description: Application-defined or object-defined error
    > >
    > > I have tested some file format.
    > >
    > > They are OK.
    > > xlExcelBook.SaveAs "C:\test.xls"
    > > xlExcelBook.SaveAs "C:\test.htm", xlHtml
    > > xlExcelBook.SaveAs "C:\test.csv", xlCSV
    > > xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText
    > >
    > > They can not work, and get an error message.
    > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    > > xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    > > xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > xlExcelBook.SaveAs "C:\test.txt", xlTextWindows
    > >
    > > Thanks advance!
    > > Liu jianzhong

    >
    > --
    >
    > Dave Peterson
    >
     
    Guest, Jul 11, 2005
    #3
  4. As I wrote before, your code worked for me in xl2003.

    Any chance that it's something else that's causing the error?

    I tried a few things, but I could never get that error--so I don't have a guess
    what it could be.

    ExcelReport wrote:
    >
    > Dave Peterson,
    >
    > My excel is Excel 2003. I follow your instruction, and get the constants:
    > (They are OK)
    > xlWorkbookNormal -4143
    > xlHtml 44
    > xlWebArchive 45
    > xlXMLSpreadsheet 46
    > xlCSV 6
    > xlCurrentPlatformText -4158
    > xlUnicodeText 42
    > xlTextPrinter 36
    >
    > (They can not work)
    > xlCSVMac 22
    > xlCSVMSDOS 24
    > xlCSVWindows 23
    > xlTextMac 19
    > xlTextMSDOS 21
    > xlTextWindows 20
    >
    > I write the source code as follows:
    > ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS
    > or
    > ActiveWorkbook.SaveAs "C:\test.txt", 21
    >
    > Best regards!
    > Liu Jianzhong
    >
    > "Dave Peterson" wrote:
    >
    > > What version of excel are you using?
    > >
    > > If you go into the VBE and hit F2 to see the object browser and search for
    > > "fileformat", do you see your format constants on that list.
    > >
    > > (I'm wondering if some of the constants changed from one version to the
    > > next--and you're using the newer constant.)
    > >
    > > ps. your snippet of code worked ok for me in xl2003.
    > >
    > >
    > >
    > > ExcelReport wrote:
    > > >
    > > > Dear,
    > > >
    > > > I run the following codes, but I can not save the file, and get an error
    > > > message. Why?
    > > >
    > > > Dim xlExcelbook As Excel.Workbook
    > > > ...
    > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > >
    > > > Err.Number : 1004
    > > > Err.Description: Application-defined or object-defined error
    > > >
    > > > I have tested some file format.
    > > >
    > > > They are OK.
    > > > xlExcelBook.SaveAs "C:\test.xls"
    > > > xlExcelBook.SaveAs "C:\test.htm", xlHtml
    > > > xlExcelBook.SaveAs "C:\test.csv", xlCSV
    > > > xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText
    > > >
    > > > They can not work, and get an error message.
    > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > xlExcelBook.SaveAs "C:\test.txt", xlTextWindows
    > > >
    > > > Thanks advance!
    > > > Liu jianzhong

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson
     
    Dave Peterson, Jul 11, 2005
    #4
  5. Guest

    Guest Guest

    Dave Peterson,

    I send you a excel file that contains a VBA program as follows. Could you
    please test it for me in your excel.
    Sub test()
    ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS ' Error,
    Err.Number=1004
    ActiveWorkbook.SaveAs "C:\test.txt", 21 ' Error,
    Err.Number=1004
    ActiveWorkbook.SaveAs "C:\test.txt", xlCurrentPlatformText 'OK
    End Sub

    Thanks for your help!
    Liu Jianzhong

    "Dave Peterson" wrote:

    > As I wrote before, your code worked for me in xl2003.
    >
    > Any chance that it's something else that's causing the error?
    >
    > I tried a few things, but I could never get that error--so I don't have a guess
    > what it could be.
    >
    > ExcelReport wrote:
    > >
    > > Dave Peterson,
    > >
    > > My excel is Excel 2003. I follow your instruction, and get the constants:
    > > (They are OK)
    > > xlWorkbookNormal -4143
    > > xlHtml 44
    > > xlWebArchive 45
    > > xlXMLSpreadsheet 46
    > > xlCSV 6
    > > xlCurrentPlatformText -4158
    > > xlUnicodeText 42
    > > xlTextPrinter 36
    > >
    > > (They can not work)
    > > xlCSVMac 22
    > > xlCSVMSDOS 24
    > > xlCSVWindows 23
    > > xlTextMac 19
    > > xlTextMSDOS 21
    > > xlTextWindows 20
    > >
    > > I write the source code as follows:
    > > ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS
    > > or
    > > ActiveWorkbook.SaveAs "C:\test.txt", 21
    > >
    > > Best regards!
    > > Liu Jianzhong
    > >
    > > "Dave Peterson" wrote:
    > >
    > > > What version of excel are you using?
    > > >
    > > > If you go into the VBE and hit F2 to see the object browser and search for
    > > > "fileformat", do you see your format constants on that list.
    > > >
    > > > (I'm wondering if some of the constants changed from one version to the
    > > > next--and you're using the newer constant.)
    > > >
    > > > ps. your snippet of code worked ok for me in xl2003.
    > > >
    > > >
    > > >
    > > > ExcelReport wrote:
    > > > >
    > > > > Dear,
    > > > >
    > > > > I run the following codes, but I can not save the file, and get an error
    > > > > message. Why?
    > > > >
    > > > > Dim xlExcelbook As Excel.Workbook
    > > > > ...
    > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > >
    > > > > Err.Number : 1004
    > > > > Err.Description: Application-defined or object-defined error
    > > > >
    > > > > I have tested some file format.
    > > > >
    > > > > They are OK.
    > > > > xlExcelBook.SaveAs "C:\test.xls"
    > > > > xlExcelBook.SaveAs "C:\test.htm", xlHtml
    > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSV
    > > > > xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText
    > > > >
    > > > > They can not work, and get an error message.
    > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextWindows
    > > > >
    > > > > Thanks advance!
    > > > > Liu jianzhong
    > > >
    > > > --
    > > >
    > > > Dave Peterson
    > > >

    >
    > --
    >
    > Dave Peterson
    >
     
    Guest, Jul 12, 2005
    #5
  6. I didn't get the file and probably wouldn't have opened it anyway.

    But I tried your code and all worked fine.

    I did have to click on the ok prompt to overwrite the existing file for the 2nd
    and 3rd lines, though.



    ExcelReport wrote:
    >
    > Dave Peterson,
    >
    > I send you a excel file that contains a VBA program as follows. Could you
    > please test it for me in your excel.
    > Sub test()
    > ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS ' Error,
    > Err.Number=1004
    > ActiveWorkbook.SaveAs "C:\test.txt", 21 ' Error,
    > Err.Number=1004
    > ActiveWorkbook.SaveAs "C:\test.txt", xlCurrentPlatformText 'OK
    > End Sub
    >
    > Thanks for your help!
    > Liu Jianzhong
    >
    > "Dave Peterson" wrote:
    >
    > > As I wrote before, your code worked for me in xl2003.
    > >
    > > Any chance that it's something else that's causing the error?
    > >
    > > I tried a few things, but I could never get that error--so I don't have a guess
    > > what it could be.
    > >
    > > ExcelReport wrote:
    > > >
    > > > Dave Peterson,
    > > >
    > > > My excel is Excel 2003. I follow your instruction, and get the constants:
    > > > (They are OK)
    > > > xlWorkbookNormal -4143
    > > > xlHtml 44
    > > > xlWebArchive 45
    > > > xlXMLSpreadsheet 46
    > > > xlCSV 6
    > > > xlCurrentPlatformText -4158
    > > > xlUnicodeText 42
    > > > xlTextPrinter 36
    > > >
    > > > (They can not work)
    > > > xlCSVMac 22
    > > > xlCSVMSDOS 24
    > > > xlCSVWindows 23
    > > > xlTextMac 19
    > > > xlTextMSDOS 21
    > > > xlTextWindows 20
    > > >
    > > > I write the source code as follows:
    > > > ActiveWorkbook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > or
    > > > ActiveWorkbook.SaveAs "C:\test.txt", 21
    > > >
    > > > Best regards!
    > > > Liu Jianzhong
    > > >
    > > > "Dave Peterson" wrote:
    > > >
    > > > > What version of excel are you using?
    > > > >
    > > > > If you go into the VBE and hit F2 to see the object browser and search for
    > > > > "fileformat", do you see your format constants on that list.
    > > > >
    > > > > (I'm wondering if some of the constants changed from one version to the
    > > > > next--and you're using the newer constant.)
    > > > >
    > > > > ps. your snippet of code worked ok for me in xl2003.
    > > > >
    > > > >
    > > > >
    > > > > ExcelReport wrote:
    > > > > >
    > > > > > Dear,
    > > > > >
    > > > > > I run the following codes, but I can not save the file, and get an error
    > > > > > message. Why?
    > > > > >
    > > > > > Dim xlExcelbook As Excel.Workbook
    > > > > > ...
    > > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > > >
    > > > > > Err.Number : 1004
    > > > > > Err.Description: Application-defined or object-defined error
    > > > > >
    > > > > > I have tested some file format.
    > > > > >
    > > > > > They are OK.
    > > > > > xlExcelBook.SaveAs "C:\test.xls"
    > > > > > xlExcelBook.SaveAs "C:\test.htm", xlHtml
    > > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSV
    > > > > > xlExcelBook.SaveAs "C:\test.txt", xlUnicodeText
    > > > > >
    > > > > > They can not work, and get an error message.
    > > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMac
    > > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVMSDOS
    > > > > > xlExcelBook.SaveAs "C:\test.csv", xlCSVWindows
    > > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMac
    > > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextMSDOS
    > > > > > xlExcelBook.SaveAs "C:\test.txt", xlTextWindows
    > > > > >
    > > > > > Thanks advance!
    > > > > > Liu jianzhong
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson
    > > > >

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson
     
    Dave Peterson, Jul 12, 2005
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Knight
    Replies:
    1
    Views:
    629
  2. Andy

    Excel marcos firing on file save as but not file save

    Andy, Aug 3, 2004, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    319
    Frank Kabel
    Aug 3, 2004
  3. Rob
    Replies:
    9
    Views:
    374
    Bob Phillips
    Jan 9, 2005
  4. harpscardiff
    Replies:
    8
    Views:
    2,021
    Jezebel
    Nov 10, 2005
  5. hon123456

    How to diasble save and save as menu but allow a save button

    hon123456, Jun 12, 2006, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    322
    Bob Phillips
    Jun 12, 2006
Loading...

Share This Page