Question: So I have already exported data using a CSV file, but as of now it is just raw data. I am trying to dsiplay the file name that it is from and the Sheet name. Here is my code so far from exporting the data. The following macro exports the data from an open excel sheet, I just run the macro and exports the data into a new workbook. Now I just want to display the file name and sheet name from the source that I exported from on the new CSV file that is created.

Sub testexport()

```
 ' export Macro

Range("B7:E26,B39:E138").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:= _
"Y:\SQCData.csv" _
, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Activate
Application.DisplayAlerts = True

```

The following range that it displays contains my data. Now my question is... How do I display the file name and the sheet name on the same excel sheet after it has been exported?

Answer: 
I wrote this a while ago. It uses a Stack. It's generic, so it can be used for other sequences as well.

```
static IEnumerable<T[]> CombinationsAnyLength<T>(params T[] values)
{
    Stack<int> stack = new Stack<int>(values.Length);
    int i = 0;
    while (stack.Count > 0 || i < values.Length) {
        if (i < values.Length) {
            stack.Push(i++);
            int c = stack.Count;
            T[] result = new T[c];
            foreach (var index in stack) result[--c] = values[index];
            yield return result;
        } else {
            i = stack.Pop() + 1;
            if (stack.Count > 0) i = stack.Pop() + 1;
        }
    }
}

CombinationsAnyLength(1, 2, 3, 4) outputs:

```

1
12
123
1234
124
13
134
14
2
23
234
24
3
34
4
Using Dennis signature:

```
    public static IEnumerable<T[]> CombinationsAnyLength<T>(params T[] values)
    {
        for(var i = 0; i < (1 << values.Length); i++)
        {
            var result = new List<T>();
            for(var j = 0; j < values.Length; j++)
            {
                if(((1 << j) & i) != 0)
                {
                    result.Add(values[j]);
                }
            }
            yield return result.ToArray();
        }
    }

```