none
cannot write to worksheet in excel file with vba code RRS feed

  • Question

  • Hi,

    I'm trying to write some standard data into rows in a worksheet. 

    The problem is this file is quite old (.xls). and it contains worksheets with vba. 

    Using interop. I cannot access the wroksheet. using epplus. I get an error specified index "-1" is not found. 

    i just tried closedxml. It doesnt fail but no data is also written to the sheet. 

    I'm not sure what to do. 

    To use epplus and closedxml I saved the file as .xlsm because i don't think they work with .xls

    Any ideas what i can try to write to this excel files.

    Also the code im using is not "bad". I can write to standard excel with no vba in it no problem. 

    Anyone ever encountered this? My preference would be to keep to file "as is" (.xls) but happy with .xlsm if I can find a solution to make it work.

    Thanks.

    Pritesh


    Tuesday, January 22, 2019 5:28 PM

Answers

  • Hello,

    This is not truly a C# topic but if you expect any assistance provide the following.

    • Code tried that failed using the code block button in the editor toolbar (second button from the right).
    • When using Interop indicating you can't access worksheets, please be more specific as there are many possible thoughts on this dependent on how you are working with the code. Same goes for the other libraries.
    • Example names of sheets attempting to access.
    • If there are any errors/exceptions thrown what are they?

    Have you tried making a copy of the file, strip out the vba code to see if the vba code is the problem?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    • Edited by KareninstructorMVP Wednesday, January 23, 2019 12:54 AM
    • Marked as answer by Pritesh3 Thursday, January 24, 2019 3:17 PM
    Wednesday, January 23, 2019 12:54 AM

All replies

  • Hello,

    This is not truly a C# topic but if you expect any assistance provide the following.

    • Code tried that failed using the code block button in the editor toolbar (second button from the right).
    • When using Interop indicating you can't access worksheets, please be more specific as there are many possible thoughts on this dependent on how you are working with the code. Same goes for the other libraries.
    • Example names of sheets attempting to access.
    • If there are any errors/exceptions thrown what are they?

    Have you tried making a copy of the file, strip out the vba code to see if the vba code is the problem?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    • Edited by KareninstructorMVP Wednesday, January 23, 2019 12:54 AM
    • Marked as answer by Pritesh3 Thursday, January 24, 2019 3:17 PM
    Wednesday, January 23, 2019 12:54 AM
  • Hi Pritesh3,

    Thank you for posting here.

    Since your question is more related to Excel, I will move it to Excel for Development for suitable support.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Wendy


    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.

    Wednesday, January 23, 2019 6:24 AM
  • Hi, 

    Thanks for the advise. I was trying to avoid messing with the excel sheet because it was quite big and I'm not great with VBA. 

    Turns out after taking out each sheet and re adding them I discovered the issue. The very 1st sheet which i ignored the most because it had very little on it had an image. Once I removed this image epplus started saving data. Bizarre error to throw "specified index -1 is out of range" but this seemed to have solved it.

    Thansk for the assist.

    Thursday, January 24, 2019 3:17 PM