Imdabaum
09-22-2010, 08:59 AM
I am exporting a recordset into Excel and emailing it to customers from Access. Everything works but I have an issue setting the formatting however.
If I use the following, it works fine.
objWorkbook.ActiveSheet.ListObjects.Add(xlSrcRange, objWorksheet.Range("A1:I6"), , xlYes).Name = _
"Table1"
objWorkbook.ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
But as you can expect not every customer has the same number of records. So I tried this little snippet that I found. But it doesn't work out.
objWorkbook.ActiveSheet.ListObjects.Add(xlSrcRange, objWorksheet.UsedRange, xlYes).Name = _
"Table1"
objWorkbook.ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
Does the .UsedRange not work within Access even if you are operating on an Excel object? Any other ideas on how to dynamically get the range of the worksheet?
If I use the following, it works fine.
objWorkbook.ActiveSheet.ListObjects.Add(xlSrcRange, objWorksheet.Range("A1:I6"), , xlYes).Name = _
"Table1"
objWorkbook.ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
But as you can expect not every customer has the same number of records. So I tried this little snippet that I found. But it doesn't work out.
objWorkbook.ActiveSheet.ListObjects.Add(xlSrcRange, objWorksheet.UsedRange, xlYes).Name = _
"Table1"
objWorkbook.ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
Does the .UsedRange not work within Access even if you are operating on an Excel object? Any other ideas on how to dynamically get the range of the worksheet?