0

The following code in theory should resize my excel tables when run from Access. I receive no errors when this is run but the tables in my excel file do not resize to all the data in the worksheets. Any help is much appreciated!

Dim appExcel As Object
Dim stWorkbook As Object
Dim varName
Set appExcel = CreateObject("Excel.Application")
Set stWorkbook = appExcel.Workbooks.Open("G:\Home\RiskMgtReports\Reporting      Database\Excel\DealerProfit.xlsx")

For Each varName In Array("DLR_ALL", "DLR_ACTIVE_DESC", "DLR_ACTIVE_ALPHA", "DLR_ACTIVE_UPF", "DLR_TERM_ALPHA", "DLR_TERM_DESC")
With stWorkbook.Worksheets(varName).ListObjects("tbl" & varName)
  .Resize stWorkbook.Worksheets(varName).Range(varName)
  With .DataBodyRange
    .Interior.Pattern = xlNone
    .Borders.LineStyle = xlNone
  End With
End With
Next varName

stWorkbook.Close SaveChanges:=True
appExcel.Quit
Set appExcel = Nothing
4

1 回答 1

0

它可能不是为 VBA 编写的,但是有一个 C# 解决方案可以sheet.Columns.AutoFit(); sheet.Rows.AutoFit();为 VBA 提供类似的东西。似乎它与我在这里找到的很接近:http ://www.vbaexpress.com/kb/getarticle.php?kb_id=40在这种情况下:Cells.EntireColumn.AutoFit

于 2013-05-15T13:13:28.683 回答