Save and Close excel file opened through OLE

Hi,
I have opened an excel file on my desktop and edited it.Now I have to save this file and close it.
Right now , I am manually saving the file and closing it. So please give the steps to automate the process of saving and closing .
Please find the code below for opening a file and editing.
report zkntest2.
INCLUDE: <line>,
         <icon>,
         <symbol>,
         ole2incl.
DATA: g_excel_app             TYPE ole2_object,
      g_excel_workbook        TYPE ole2_object,
      g_excel_worksheet       TYPE ole2_object,
      g_excel_usedrange       TYPE ole2_object,
      g_excel_cell            TYPE ole2_object,
      g_excel_return          TYPE ole2_object.
data :H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
      H_MAP TYPE OLE2_OBJECT,          " workbook
      H_ZL TYPE OLE2_OBJECT,           " cell
      H_F TYPE OLE2_OBJECT.            " font
CONSTANTS:c_appl(17)              TYPE c VALUE 'Excel.Application'.
SELECTION-SCREEN BEGIN OF BLOCK blk1 with frame title text-001.
PARAMETERS p_ofile LIKE rlgrap-filename default 'C:\layout.xls'.
SELECTION-SCREEN END OF BLOCK blk1.
CREATE OBJECT g_excel_app c_appl.
CALL METHOD OF g_excel_app 'Workbooks' = g_excel_workbook.
CALL METHOD OF g_excel_workbook 'Open'
  EXPORTING #1 = p_ofile.
SET PROPERTY OF g_excel_app 'Visible' = 1.
CALL METHOD OF g_excel_app 'Workbooks' = H_MAPL.
PERFORM FILL_CELL USING  4 9 1 'Kiran'(001).
PERFORM FILL_CELL USING  5 9 1 'Ref#'(002).
PERFORM FILL_CELL USING  6 9 1 'Claim#'(003).
PERFORM FILL_CELL USING  7 9 1 'Location'(004).
FREE OBJECT g_excel_app.
FORM FILL_CELL USING I J BOLD VAL.
  CALL METHOD OF g_excel_app 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
  SET PROPERTY OF H_ZL 'Value' = VAL .
  GET PROPERTY OF H_ZL 'Font' = H_F.
  SET PROPERTY OF H_F 'Bold' = BOLD .
ENDFORM.                    "FILL_CELL

Try add this code below.
  CALL METHOD OF G_EXCEL_APP 'ActiveWorkbook' = G_EXCEL_WORKBOOK.
  CALL METHOD OF G_EXCEL_WORKBOOK 'SaveAs' EXPORTING #1 = '1.xls'.
  CALL METHOD OF G_EXCEL_WORKBOOK 'Close'.
  CALL METHOD OF G_EXCEL_APP 'Quit'.
  FREE G_EXCEL_APP.

Similar Messages

  • Save and close excel file using C#.

    I am not sure why I get the following error for the below code.  Everything seems to work otherwise.
    Error found: System.Runtime.InteropServices.COMException (0x8002000B): Invalid index. (Exception from HRESULT: 0x8002000
    B (DISP_E_BADINDEX))
    Application _application;public void CloseFile(string filename, bool isSaveChanges)
    _application.Workbooks[filename].Close(SaveChanges: isSaveChanges);

    I' work with excel files with connection you can save data and  close connection Easy.
     //connection String for xls file format.
                        if (fileExtension == ".xls")
                            excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                        //connection String for xlsx file format.
                        else if (fileExtension == ".xlsx")
                            excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                        //Create Connection to Excel work book and add oledb namespace
                        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                        excelConnection.Open();
    DataTable dt = new DataTable();
                        dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                        if (dt == null)
                            return null;
                        String[] excelSheets = new String[dt.Rows.Count];
                        int t = 0;
                        //excel data saves in temp file here.
                        foreach (DataRow row in dt.Rows)
                            excelSheets[t] = row["TABLE_NAME"].ToString();
                            t++;
                        OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString);
                        string query = string.Format("Select * from [{0}]", excelSheets[0]);
                        using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1))
                            dataAdapter.Fill(ds);
    Best Regards
    Hakim.

  • Automatically open, save and close excel?

    I need import data from Excel to SQL.
    Now, I use tSQL to directly read the excel files and transform to the SQL table.
    As the user Excel is not a good format for SQL to read, I need use formula to transform the excel to be a SQL readable format.
    Now, I add a sheet to copy the data from the sheet which user input the data and then ask the user to copy the excel to a specific location for import.
    However, this will make the data in the excel double and result a large excel file.
    I am thinking if it is possible to create a excel to use formula to copy the data from another excel.
    Then, I need find some method to open that excel, let the content refresh from the source excel, save and close it.
    Then I can directly use this excel for data import.
    Is there any simple way to do so? I don't know marco much...
    Ivan

    No formula could do this (Automatically open, save and close excel).
    You need to recode a marco or write a macro. Why donot you ask in msdn?
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc
    example:
    Sub auto_open()
    Application.OnTime Now + TimeValue("00:01:00"), "wswx"
    End Sub
    Sub
    wswx() If Not ThisWorkbook.Saved
    Then ThisWorkbook.Save
    ThisWorkbook.Close
    End Sub
    KR

  • Save and close InDesign file CS4 JS

    Hi, I need to save and close InDesign file after export pdf was done. Once export is complete the script opens the pdf file and the script gets interrupted. Here what I was trying and I am not sure if it even in the right direction:
    #targetengine "session"
    main();
    function main(){
        var myApplicationEventListener = app.eventListeners.add("afterExport",
        mySaveInDesign, false);
        var myDocumentEventListener = app.documents.item(0).eventListeners.add
        ("afterExport", mySaveInDesign, false);
        app.scriptPreferences.version = 6.0;
    var myEventNames = ["afterExport"] ;
    function mySaveInDesign(myEvent){
        var myDocument = myEvent.parent;
        saveInDesign ();
    function saveInDesign (){
        //myDocument.save(myDocument);
        app.activeDocument.save(myDocument);
        app.activeDocument.close(myDocument);
    Your help is highly appreciated.
    Yulia

    Save either takes no argument (equivalent to the File/Save menu option) or a file path, equivalent to File/Save As.
    So, your save commands aren't going to work as written. You either need just save(); or save(myDocument.fullName);
    Dave

  • Welcome window problem.  appears every time i save and close a file of photoshop

    How to fix a bug regarding welcome window. this window appears every time i save and close a file of photoshop, its started after the last update 2014.2.0

    See this document: Troubleshoot Welcome Screen in Photoshop
    Scroll all the way down to the bottom. There's a check box "Don't Show Welcome Screen Again"
    You can relaunch the screen at a later date by selecting Help>Welcome Screen...
    ~ Arpit

  • Hello, Indesign 6 will not allow me to save and close my file

    Hello, Indesign 6 will not allow me to save and close my file

    Try exporting to .idml. If that works, openthe .idml and save as a new .indd.
    If it doesn't work, force quit ID and then restart. Auto-recovery should kick in and reopen the file at about the last state, then try again.

  • Use VBA and Excel to open Dreamweaver HTML (CS5), find and replace text, save and close

    I wish to use VBA and Excel to programmatically open numbered Dreamweaver HTML (CS5) and find and replace text in the code view of these files, save and close them.
    I have  5000 associations between Find: x0001 and Replace: y0001 in an Excel sheet.
    I have the VBA written but do not know how to open, close and save the code view of the ####.html files. Please ... and thank you...
    [email protected]

    This is actually the code view of file ####.html that I wish to find and replace programmatically where #### is a four digit number cataloguing each painting.... In 1995 I thought this was clever... maybe not so clever now :>)) Thank you for whatever you can do Rob!
    !####.jpg!
    h2. "Name####"
    Oils on acrylic foundation commercial canvas - . xx X xx (inches) Started
    Back of the Painting In Progress </p> </body> </html>
    Warmest regards,
    Phil the Forecaster, http://philtheforecaster.blogspot.ca/ and http://phils-market.blogspot.ca/

  • I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Why?

    I have an iMac. , mid 2007.  Frequently, when I take an action, the little color wheel starts spinning and goes on for quite awhile.  Save a file, close a file, open a file, open a window, it's all random.  Somtimes it stalls, sometimes it doesn't.  Sometimes long, sometims short.  Why is this happening?

    Consider adding more memory. Be sure you have adequate free space on the hard drive - 15 GBs or 10% of the drive's capacity, whichever is greater. Do not run too many applications concurrently. Visit The XLab FAQs and read the FAQ on resolving the SBBOD.
    Do some maintenance:
    Repair the Hard Drive and Permissions
    Boot from your Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    Kappy's Personal Suggestions for OS X Maintenance
    For disk repairs use Disk Utility.  For situations DU cannot handle the best third-party utilities are: Disk Warrior;  DW only fixes problems with the disk directory, but most disk problems are caused by directory corruption; Disk Warrior 4.x is now Intel Mac compatible. Drive Genius provides additional tools not found in Disk Warrior.  Versions 1.5.1 and later are Intel Mac compatible.
    OS X performs certain maintenance functions that are scheduled to occur on a daily, weekly, or monthly period. The maintenance scripts run in the early AM only if the computer is turned on 24/7 (no sleep.) If this isn't the case, then an excellent solution is to download and install a shareware utility such as Macaroni, JAW PseudoAnacron, or Anacron that will automate the maintenance activity regardless of whether the computer is turned off or asleep.  Dependence upon third-party utilities to run the periodic maintenance scripts was significantly reduced since Tiger.  These utilities have limited or no functionality with Snow Leopard or Lion and should not be installed.
    OS X automatically defragments files less than 20 MBs in size, so unless you have a disk full of very large files there's little need for defragmenting the hard drive. As for virus protection there are few if any such animals affecting OS X. You can protect the computer easily using the freeware Open Source virus protection software ClamXAV. Personally I would avoid most commercial anti-virus software because of their potential for causing problems. For more about malware see Macintosh Virus Guide.
    I would also recommend downloading a utility such as TinkerTool System, OnyX 2.4.3, or Cocktail 5.1.1 that you can use for periodic maintenance such as removing old log files and archives, clearing caches, etc.
    For emergency repairs install the freeware utility Applejack.  If you cannot start up in OS X, you may be able to start in single-user mode from which you can run Applejack to do a whole set of repair and maintenance routines from the command line.  Note that AppleJack 1.5 is required for Leopard. AppleJack 1.6 is compatible with Snow Leopard. There is no confirmation that this version also works with Lion.
    When you install any new system software or updates be sure to repair the hard drive and permissions beforehand. I also recommend booting into safe mode before doing system software updates.
    Get an external Firewire drive at least equal in size to the internal hard drive and make (and maintain) a bootable clone/backup. You can make a bootable clone using the Restore option of Disk Utility. You can also make and maintain clones with good backup software. My personal recommendations are (order is not significant):
    Carbon Copy Cloner
    Data Backup
    Deja Vu
    SuperDuper!
    SyncTwoFolders
    Synk Pro
    Synk Standard
    Tri-Backup
    Visit The XLab FAQs and read the FAQs on maintenance, optimization, virus protection, and backup and restore.
    Additional suggestions will be found in Mac Maintenance Quick Assist.
    Referenced software can be found at CNet Downloads or MacUpdate.
    Be sure you have an adequate amount of RAM installed for the number of applications you run concurrently. Be sure you leave a minimum of 10% of the hard drive's capacity as free space.

  • Keep getting corrupted temp save file when I save and close.

    When I save and close a numbers spreadsheet, about 20% of the time I will be left with the normal file and a weird temporary file with a "~" on the end of the file name.  I can't delete the file or do anything with it.  It will let me open it, but even when I save it still says I cant delete because the file is in use.
    Example-
    Work on spreadsheet1.  Hit save and then close.
    In finder I am left with-
    spreadsheet1
    spreadsheet1~
    "spreadsheet1" is the correct file and it works and functions normally, but "spreadsheet1~" is corrupt and I cant seem to delete it.  I always get "The operation can’t be completed because the item “spreadsheet1~” is in use.
    What is causing this and how can I get rid of those files?

    I think I would ignore the files and not worry about them.  Are you experiencing any undesirable effects of these files-- aside from seeing them there?

  • Firefox asks (twice) to save and close tabs, on new open windows without tabs, when i close them.

    About one month ago, i started to receive a message box from firefox, asking if i wanted to save and close tabs, on newly open windows (and pop-ups) without any tabs open on them.
    And everytime i close the windows without tabs, firefox asks it twice...
    I did not made any changes, so i don't know why it started doing this.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Open, Write and Close the file using Powershell

    Hi All,
    I need to create/open a file and write some data into it and close that file.
    Could anyone please help me with this.
    Thanks.

    You don't need to explicitly create, open, or close a file in Powershell.  Here are some ways to write to a file, in addition to New-Item:
    $text = 'Hello World'
    # Create file:
    $text | Set-Content 'file.txt'
    #or
    $text | Out-File 'file.txt'
    #or
    $text > 'file.txt'
    # Append to file:
    $text | Add-Content 'file.txt'
    #or
    $text | Out-File 'file.txt' -Append
    #or
    $text >> 'file.txt'
    Grant Ward, a.k.a. Bigteddy
    The problem with Out-File is that it works like the console. When text is output, it will be truncated if it is wider than the default. So if you are looking for something where you need to store lots of long strings, then you may want to choose a different
    route, or ensure than you specify a width for your output.
    http://technet.microsoft.com/en-us/library/ee176924.aspx
    For example to get 200 characters of width:
    $text | Out-File
    'myfile.txt' -width 200
    I do not know for certain if there is a limit to how wide it can be. I also assume the default is the standard console width (80 characters I believe.)

  • Can TestStand open, read, write and close binary files?

    From a TestStand sequence, I need to open, read, write and close binary files. Does TestStand support this capability?

    Christine -
    In the past I have used the C/C++ Adapter to call directly into the CVI RTE functions. The CVI functions I have used are OpenFile, WriteFile and CloseFile. The functions are exported from the DLL as CVI_OpenFile, CVI_WriteFile, and CVI_CloseFile. I just had to make sure that on termination of the sequence, that the integer handle was properly released by calling the close function.
    If you are using LabVIEW, you could call directly into the low level VIs to do a similar set of operations.
    Scott Richardson (NI)
    Scott Richardson
    National Instruments

  • Close Excel File after getting data from it

    Hi!
    I have a big vi to make data aquisiton from a spectrometer. I have the aquisition part and the "save to spreeadsheet" part also. Now I want to make a button to open the data from the excel file and show it in a xy chart. I had some problems but now its working except one important thing. After I read the data from the file and have it in the chart, it seems like the file it's not closed cause if I try to open it in excel, it "hangs" the computer. If I stop the vi, there's no problem. What can I do? I saw here in the forum that its not necessary to open or/and close spreedsheet files but i think this problem is because the file it's not "released" or something. Any help would be great.
    Here's the part of the vi that reads the file, and the file itself.
    Thanks in advance

    Strange. I made the attachment. Anyway, here it is:
    Attachments:
    open data file.vi ‏17 KB
    scan 11h21m17s .xls ‏44 KB

  • LIST_FROM_MEMORY - Excel File - Open data set

    Hello,
    A long time ago I asked people here how to convert a submit program to html and using open/transfer/close data set altoghter. I got a lot of help for that and I am greatful.
    However, I may need to try something and would like to ask how does this apply when you want to transfer <b>LIST_FROM_MEMORY -> Excel File -> Open/transfer/close data set</b>leading it to be saved to the application server.
    Thank you all and good day.

    Do we have to write the list into application server in XL format?
    Once we get the data from LIST_FROM_MEMORY, then write this data into application server using DATASETS
    Refer to these links
    How can I upload data from excel file from Application Server?
    Regds
    Manohar

  • CRM 2013 - "Save and Close" button behavnig like "Save and New"

    Hi,
    I am working in CRM 2013. I have a scenario in which I am saving new opportunity product record through javascript and preventing original save of CRM. Save is working fine. After save, I need to refresh the screen. So I have used "Xrm.Utility.openEntityForm"
    to open newly created item in edit mode. When I click on "Save and Close" button on this new form in edit mode, instead of closing the opportunity product screen, it opens new entity form. So in short, after saving the record, if I click on "Save
    and Close", it behaves like "Save and New".
    Any one facing such issue?

    Save & Close seems to behave like the Save & "Back" Button, so the form tries to return to the new form, that was opened before.
    But I have no solution for this behavior...

Maybe you are looking for