Forum Discussion
Good idea to check the Active workbook.
Turns out it is null, but I can't imagine why.
The file path I create is valid: C:\Repositories\Git\Repos\Automation\Automation\ExcelSheets\Fees Test Cases.xlsx
Is there something more to opening files with variable names that I am missing?
Another thought...
What you are calling in your function is a file that is in your Git repository... I'm not 100% familiar with Git but I know that some source control applications like TFS and the old VisualSourceSafe have a possible setup that files are marked "Read only" if they are not actually checked out in the source control. I wonder if what you're having problems with is if the file is, for some reason, "read only", and therefore cannot be opened by excel.Workbooks.
I'm not 100% familiar with using the Excel.Application via COM like you are but, according to https://msdn.microsoft.com/en-us/library/office/ff194819.aspx there is a special parameter to add to your open call to indicate to be opened in read-only... which means that I can probably safely assume that without that parameter, it's attempting to be opened in read/write mode... and if the file IS marked as read-only, the open call is probably failing...
- frank_vanderstr10 years agoContributor
I don't believe the file is read only. I don't see any setting in Git that would specify it, but if it was read only when I open the file manually I would have to enable editing to make any changes in Excel, and I am able to do any editing freely upon opening it.
I can look into the possibility of missing a needed parameter. Just seems strange that the code will work in other places without it.
- tristaanogre10 years agoEsteemed Contributor
Yeah, I'm leaning toward this not being a specific problem with your code but more something having to do with your specific file.
Something else to consider: While the file might not be marked as read-only, it's presence in a Git repository I think is still a significant factor. While it might not be read-only, I know that some source control apps have monitoring services and such that, when a file changes, they do some stuff to do an automatic check out or at least monitor activity on the file. So, I think Git might be our culprit here somehow.
To test the theory... move or copy the file to a different drive location that is not in a Git repository and alter your code to point there and see if you get the same problem. If you do, then it's something else... if you don't then that narrows it down to Git being the issue.