Using the SaveAs in Excel not working with Ruby

Discussion in 'Ruby' started by anon1m0us@yahoo.com, Dec 12, 2006.

  1. Guest

    Hi;
    I need to save an Excel Spreadsheet with Ruby. I used the Save AND
    SaveAs methods, but each time I get prompted "Do you want to save the
    changes you made..." How can I save the workbook without this prompt.
    In addition, is there away to add a timestamp to the save file
    like.....application12122006.xls or any format that contains a time
    stamp?
    , Dec 12, 2006
    #1
    1. Advertising

  2. mully Guest

    wrote:
    > How can I save the workbook without this prompt.


    Where xl is your Excel Application object and wb is your Workbook
    object...

    xl.DisplayAlerts = 0
    wb.SaveAs(xlsname)
    xl.DisplayAlerts = 1

    > In addition, is there away to add a timestamp to the save file
    > like.....application12122006.xls or any format that contains a time
    > stamp?


    Something like this...

    xlsname = 'application' + Time.now.strftime("%m%d%y") + '.xls'

    Mully
    mully, Dec 12, 2006
    #2
    1. Advertising

  3. Guest

    Thanks...that did the trick!

    mully wrote:
    > wrote:
    > > How can I save the workbook without this prompt.

    >
    > Where xl is your Excel Application object and wb is your Workbook
    > object...
    >
    > xl.DisplayAlerts = 0
    > wb.SaveAs(xlsname)
    > xl.DisplayAlerts = 1
    >
    > > In addition, is there away to add a timestamp to the save file
    > > like.....application12122006.xls or any format that contains a time
    > > stamp?

    >
    > Something like this...
    >
    > xlsname = 'application' + Time.now.strftime("%m%d%y") + '.xls'
    >
    > Mully
    , Dec 12, 2006
    #3
  4. Gustav Paul Guest

    wrote:
    > Hi;
    > I need to save an Excel Spreadsheet with Ruby. I used the Save AND
    > SaveAs methods, but each time I get prompted "Do you want to save the
    > changes you made..." How can I save the workbook without this prompt.
    > In addition, is there away to add a timestamp to the save file
    > like.....application12122006.xls or any format that contains a time
    > stamp?
    >
    >
    >
    >

    Hey

    I think you can use

    book.close

    passing either 1 or 0 (I can't remember which)
    Also, I can't remember if you need to call SaveAs first.

    This should work:

    book = #get workbook
    book.SaveAs "SomeFile.xls"
    book.close(0)

    Hope this helps
    Gustav Paul
    Gustav Paul, Dec 12, 2006
    #4
  5. Ivor Guest

    I am guessing the (0) in close(0) refers to the number of the book that
    is open, which could mean that if you had a book open and you open a new
    book, then this will fail.

    try close("SomeFile.xls") and let me know if that works. I know from the
    VBA that you could refer to the book by using the filename as the reference.
    the all open workbooks lie in a collection hence the need for a reference.

    it's been a long time since I have done any VBA, which is a good thing!
    ivor

    Gustav Paul wrote:
    > wrote:
    >
    >> Hi;
    >> I need to save an Excel Spreadsheet with Ruby. I used the Save AND
    >> SaveAs methods, but each time I get prompted "Do you want to save the
    >> changes you made..." How can I save the workbook without this prompt.
    >> In addition, is there away to add a timestamp to the save file
    >> like.....application12122006.xls or any format that contains a time
    >> stamp?
    >>
    >>
    >>
    >>
    >>

    > Hey
    >
    > I think you can use
    >
    > book.close
    >
    > passing either 1 or 0 (I can't remember which)
    > Also, I can't remember if you need to call SaveAs first.
    >
    > This should work:
    >
    > book = #get workbook
    > book.SaveAs "SomeFile.xls"
    > book.close(0)
    >
    > Hope this helps
    > Gustav Paul
    >
    >
    >
    >
    Ivor, Dec 12, 2006
    #5
  6. Guest

    Ok, this code provides the date..
    xlsname = 'application' + Time.now.strftime("%m%d%y") + '.xls'
    If i want to add a time stamp to? is it ("%m%d%y%h%mm%s")???


    Ivor wrote:
    > I am guessing the (0) in close(0) refers to the number of the book that
    > is open, which could mean that if you had a book open and you open a new
    > book, then this will fail.
    >
    > try close("SomeFile.xls") and let me know if that works. I know from the
    > VBA that you could refer to the book by using the filename as the reference.
    > the all open workbooks lie in a collection hence the need for a reference.
    >
    > it's been a long time since I have done any VBA, which is a good thing!
    > ivor
    >
    > Gustav Paul wrote:
    > > wrote:
    > >
    > >> Hi;
    > >> I need to save an Excel Spreadsheet with Ruby. I used the Save AND
    > >> SaveAs methods, but each time I get prompted "Do you want to save the
    > >> changes you made..." How can I save the workbook without this prompt.
    > >> In addition, is there away to add a timestamp to the save file
    > >> like.....application12122006.xls or any format that contains a time
    > >> stamp?
    > >>
    > >>
    > >>
    > >>
    > >>

    > > Hey
    > >
    > > I think you can use
    > >
    > > book.close
    > >
    > > passing either 1 or 0 (I can't remember which)
    > > Also, I can't remember if you need to call SaveAs first.
    > >
    > > This should work:
    > >
    > > book = #get workbook
    > > book.SaveAs "SomeFile.xls"
    > > book.close(0)
    > >
    > > Hope this helps
    > > Gustav Paul
    > >
    > >
    > >
    > >
    , Dec 12, 2006
    #6
    1. Advertising

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. Mark Ritchey
    Replies:
    0
    Views:
    8,270
    Mark Ritchey
    Dec 10, 2003
  2. =?Utf-8?B?UmVkZHk=?=
    Replies:
    5
    Views:
    2,181
    =?Utf-8?B?UmVkZHk=?=
    Dec 28, 2005
  3. Chris
    Replies:
    3
    Views:
    323
  4. N. Shehzad
    Replies:
    2
    Views:
    820
    Andrew Morton
    Apr 22, 2010
  5. N. Shehzad

    SaveAs excel Dialog and IIS ConnectionTimeOut

    N. Shehzad, Apr 20, 2010, in forum: ASP .Net Security
    Replies:
    0
    Views:
    784
    N. Shehzad
    Apr 20, 2010
Loading...

Share This Page