+ Reply to Thread
Results 1 to 7 of 7

Close a File and Excel ??

  1. #1
    Registered User
    Join Date
    11-14-2005
    Posts
    9

    Close a File and Excel ??

    I have a macro to print the xls file, but before i print the file i want to close the file and the excel ??

    How can i do ?? its possible ??

  2. #2
    Tom Ogilvy
    Guest

    Re: Close a File and Excel ??

    Use ontime in the BeforePrint event to schedule a macro to run that will
    close excel.

    --
    Regards,
    Tom Ogilvy

    "rvillanueva" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I have a macro to print the xls file, but before i print the file i want
    > to close the file and the excel ??
    >
    > How can i do ?? its possible ??
    >
    >
    > --
    > rvillanueva
    > ------------------------------------------------------------------------
    > rvillanueva's Profile:

    http://www.excelforum.com/member.php...o&userid=28814
    > View this thread: http://www.excelforum.com/showthread...hreadid=537635
    >




  3. #3
    Dave Patrick
    Guest

    Re: Close a File and Excel ??

    Try something like;

    Dim xlApp
    Dim xlBook
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Open("C:\data\excel\TrainLoading.xlt")
    xlApp.Sheets("Data").Range("e1") = readdate1
    xlApp.Sheets("Data").Range("e2") = Forms!frmLoading.opt1.Value
    xlApp.Run "BothPrint"
    'xlApp.Application.Visible = True
    xlBook.Close (False)
    xlApp.Quit
    Set xlApp = Nothing
    Set xlBook = Nothing


    --

    Regards,

    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    http://www.microsoft.com/protect

    "rvillanueva" wrote:
    |
    | I have a macro to print the xls file, but before i print the file i want
    | to close the file and the excel ??
    |
    | How can i do ?? its possible ??
    |
    |
    | --
    | rvillanueva
    | ------------------------------------------------------------------------
    | rvillanueva's Profile:
    http://www.excelforum.com/member.php...o&userid=28814
    | View this thread: http://www.excelforum.com/showthread...hreadid=537635
    |



  4. #4
    Tom Ogilvy
    Guest

    Re: Close a File and Excel ??

    Just to add, if you have a macro in the workbook being printed that is doing
    the printing, as soon as you close the workbook, the macro stops.

    --
    Regards,
    Tom Ogilvy

    "rvillanueva" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I have a macro to print the xls file, but before i print the file i want
    > to close the file and the excel ??
    >
    > How can i do ?? its possible ??
    >
    >
    > --
    > rvillanueva
    > ------------------------------------------------------------------------
    > rvillanueva's Profile:

    http://www.excelforum.com/member.php...o&userid=28814
    > View this thread: http://www.excelforum.com/showthread...hreadid=537635
    >




  5. #5
    Registered User
    Join Date
    11-14-2005
    Posts
    9
    Tom:

    1) Im a rookie using macros, how can i do to use an event ?
    Use ontime in the BeforePrint event to schedule a macro to run that will
    close excel.

    2) I run the macro and when i print the sheet alway ask me for the printer and all the normal params (copy, etc), how can i do to send in auto way to the default printer ?

    3) If i understand when i close the xls, the macro stops then the excel still active no ??

    Thanks
    Ricardo

  6. #6
    Tom Ogilvy
    Guest

    Re: Close a File and Excel ??

    See Chip Pearson's page on Events for an overview and his page on Ontime

    http://www.cpearson.com/excel/events.htm

    http://www.cpearson.com/excel/ontime.htm

    ActiveWorkbook.Printout

    or ActiveSheet.Printout

    don't raise any dialogs for me.

    --
    Regards,
    Tom Ogilvy


    "rvillanueva" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Tom:
    >
    > 1) Im a rookie using macros, how can i do to use an event ?
    > Use ontime in the BeforePrint event to schedule a macro to run that
    > will
    > close excel.
    >
    > 2) I run the macro and when i print the sheet alway ask me for the
    > printer and all the normal params (copy, etc), how can i do to send in
    > auto way to the default printer ?
    >
    > 3) If i understand when i close the xls, the macro stops then the excel
    > still active no ??
    >
    > Thanks
    > Ricardo
    >
    >
    > --
    > rvillanueva
    > ------------------------------------------------------------------------
    > rvillanueva's Profile:

    http://www.excelforum.com/member.php...o&userid=28814
    > View this thread: http://www.excelforum.com/showthread...hreadid=537635
    >




  7. #7
    Registered User
    Join Date
    11-14-2005
    Posts
    9
    Thanks for your help,

    Ricardo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1