none
display specific excel sheet RRS feed

  • Question

  • Hi,

    I have a windows form application and I have an excel file that some processes are be done on it, finally I want to show the output excel file but not the input file. if I use xlap.visible = true, it show input and output file on output but I need showing the output file only. can you help me?

    Saturday, January 6, 2018 3:44 PM

Answers

  • Hello nadianaji,

    The issue does exist. You could not copy and paste range directly since they are not in the same application instance.

    Since your original issue has been resolved and I note that you have also post a new thread for the copy issue, I would suggest you mark answer to close the thread and we will continue the copy issue on your new thread. 

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by nadianaji Monday, January 15, 2018 3:38 PM
    Monday, January 15, 2018 2:30 AM

All replies

  • n,
    re: hide an excel workbook

    An Excel workbook can have multiple worksheets.
    You might want to do your processes in one worksheet and show the output in another worksheet, all in the same workbook.
    Only one sheet in a workbook must remain visible; all others can be hidden. 
    In fact, a worksheet does not need to be visible in order to use it.  You could hide it and leave it that way...
       xlApp.Workbooks("Processes.xlsx").Worksheets("Input").Visible = False

    If the above is not practical, then you could close the processes workbook before making the application visible...
       xlApp.Workbooks("Processes.xlsx").Close SaveChanges:=True    ' False is faster
    -or-
    Since an Excel add-in is nothing more than a hidden workbook, this might work for you...
       xlApp.Workbooks("Processes.xlsx").IsAddin = True

    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)
    Saturday, January 6, 2018 11:20 PM
  • Hi, 

    this is my variables and my input and result excel file are in different workbooks and I want to show the output workbook only. I want to show Targetworkboo1 in output but with this code, sourceworkbook and Targetworkbook1 will be shown in output. how should I do it?

    Excel.Application xlApp = new Excel.Application();
    Excel.Workbook SourceWorkbook;
    xlApp.Visible = true;
    Excel.Workbook TargetWorkbook1;
    Excel.Worksheet SourceWorksheet;
    Excel.Worksheet TargetWorksheet1;
    SourceWorksheet = SourceWorkbook.Worksheets[1];
    TargetWorkbook1 = xlApp.Workbooks.Add();
    TargetWorksheet1 = TargetWorkbook1.Worksheets[1];


    • Edited by nadianaji Sunday, January 7, 2018 7:18 AM
    Sunday, January 7, 2018 7:16 AM
  • n,
    I'm not able to provide the C# code.
    If you don't get another response in a day or so, you should post a new question in the forum.

    '---
    Jim Cone

    Sunday, January 7, 2018 4:32 PM
  • Hello nadianaji,

    You could create two application instances. One is for SourceWorkBook and the other is for TargetWorkbook. You could hide application instances visible as false for the SourceWorkbook's application.

    Here is the example.

                Excel.Application xlApp= new Excel.Application();
                Excel.Application targetApp= new Excel.Application();
                xlApp.Visible = false;
                targetApp.Visible = true;
    
                Excel.Workbook SourceWorkbook;
                Excel.Workbook TargetWorkbook1;
    
                Excel.Worksheet SourceWorksheet;
                Excel.Worksheet TargetWorksheet1;
    
                SourceWorkbook = xlApp.Workbooks.Open(@"C:\Users\Administrator\Desktop\Base.xls");    
                SourceWorksheet = SourceWorkbook.Worksheets[1];
    
                TargetWorkbook1 = targetApp.Workbooks.Add();
                TargetWorksheet1 = TargetWorkbook1.Worksheets[1];

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by nadianaji Monday, January 8, 2018 9:41 AM
    • Unmarked as answer by nadianaji Tuesday, January 9, 2018 8:46 AM
    Monday, January 8, 2018 8:35 AM
  • Hi, this code produce an error" "Copy method of Range class failed"." and I think this is because of different excel workbook. my code is as bellow and in last line I receive this error.

    Excel.Application xlApp = new Excel.Application();       
    Excel.Workbook SourceWorkbook;
    Excel.Application tarApp = new Excel.Application();
    SourceWorkbook = xlApp.Workbooks.Open(@filePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
    
    tarApp.Visible = true;
    Excel.Workbook TargetWorkbook1;
    Excel.Worksheet SourceWorksheet;
    Excel.Worksheet TargetWorksheet1;
    SourceWorksheet = SourceWorkbook.Worksheets[1];
    TargetWorkbook1 = tarApp.Workbooks.Add();
    TargetWorksheet1 = TargetWorkbook1.Worksheets[1];
    xlApp.ScreenUpdating = false;
    SourceWorksheet.Columns.AutoFilter(Y, "1");
    SourceWorksheet.Columns.AutoFilter(P, "9100");
    SourceWorksheet.Columns.AutoFilter(DP, "9100");
    SourceWorksheet.UsedRange.Copy(TargetWorksheet1.Range["A1"]);

    Tuesday, January 9, 2018 8:49 AM
  • Hello nadianaji,

    The issue does exist. You could not copy and paste range directly since they are not in the same application instance.

    Since your original issue has been resolved and I note that you have also post a new thread for the copy issue, I would suggest you mark answer to close the thread and we will continue the copy issue on your new thread. 

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by nadianaji Monday, January 15, 2018 3:38 PM
    Monday, January 15, 2018 2:30 AM