1

I have created a Microsoft Excel workbook project in Excel. What I want to do is to take in data from a text file and open that up in my worksheet. To do this I tired usign the following inside of the Sheet1.cs file:

public partial class Sheet1
{
    private void Sheet1_Startup(object sender, System.EventArgs e)
    {
        this.Application.Workbooks.OpenText(@"C:\GG_Provider.txt",
            missing, 1,
            Excel.XlTextParsingType.xlDelimited,
            Excel.XlTextQualifier.xlTextQualifierNone,
            missing, missing, missing, missing, missing, true, "|",
            missing, missing, missing, missing, missing, missing);
    }

This opens up the data successfully however it does so in a brand new workbook. So when I run my application it opens up two different workbooks. One blank one and one with all of the data in it and a worksheet with the same name as the text file.

What can I do so that the data goes into the original workbook that is currently blank?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Sperick
  • 2,691
  • 6
  • 30
  • 55
  • 1
    It doesn't look like that method can work in the manner you want. Check this link for alternative methods: http://stackoverflow.com/questions/11267459/vba-importing-text-file-into-excel-sheet – Malk Dec 13 '13 at 18:42
  • 1
    you are using the `.OpenText` method which will open a new workbook. Use query tables instead as shown in the link given by @Malk – Siddharth Rout Dec 13 '13 at 19:09

0 Answers0