Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Make Selection Based Off Selected Worksheet

$
0
0

//Declaring variables

string[] listOfQuery = { "qry_sales_for_joe", "qry_sales_for_mitch", "qry_sales_for_beth", "qry_sales_for_sarah" }; string path = @"C:\\Database\\"; string file = "Test.mdb"; //Creating a workbook with 4 worksheets oXL = new Microsoft.Office.Interop.Excel.Application(); oWB = oXL.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel._Worksheet worksheet = null; Sheets xlSheets = null; Worksheet xlNewSheet = null; xlSheets = oWB.Sheets as Sheets; oXL.Visible = true; worksheet = oWB.Worksheets[1]; worksheet.Name = "Joe"; worksheet = oWB.Worksheets[2]; worksheet.Name = "Mitch"; worksheet = oWB.Worksheets[3]; worksheet.Name = "Beth"; xlNewSheet = (Worksheet)xlSheets.Add(xlSheets[1], Type.Missing, Type.Missing, Type.Missing); xlNewSheet.Name = "Sarah";

I am using the above code to create a Excel Workbook and add 4 worksheets and name them.  Now what I need to do is import a query based off of which worksheet I am on.  For example, each query corresponds to a particular worksheet.  What would be the best way for me to iterate through the worksheets and import the proper query?

Fir example sheet 3 "Beth" would need "qry_sales_for_Beth" and so on...


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>