我尝试将Excel中的数据格式化为Access中的表格失败。我希望有人能告诉我我做错了什么:
第一种方式:
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = False
appExcel.Workbooks.Open (strFileName)
appExcel.Workbooks(1).Sheets(lngSheet).ListObjects.Add(xlSrcRange, Range("A1:O6"), , xlYes).Name = _
"Table1"
appExcel.Workbooks(1).Sheets(lngSheet).ListObjects("Table1").TableStyle = "TableStyleMedium1"
第二种方式:
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = False
appExcel.Workbooks.Open (strFileName)
Set wb = appExcel.Workbooks.Open(strFileName)
Set ws = wb.Sheets(1)
ws.ListObjects.Add(xlSrcRange, Range("$A$1:$O$6"), , xlYes).Name = _
"Table2"
ws.ListObjects("Table2").TableStyle = "TableStyleMedium15"
第三种方式:
Dim wb As Object
Dim ws As Object
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = False
appExcel.Workbooks.Open (strFileName)
Set wb = appExcel.Workbooks.Open(strFileName)
Set ws = wb.Sheets(1)
ws.ListObjects.Add(xlSrcRange, Range("$A$1:$O$6"), , xlYes).Name = _
"Table2"
ws.ListObjects("Table2").TableStyle = "TableStyleMedium15"
我感谢任何帮助。谢谢!
答案 0 :(得分:0)
我的范围错了。修正了范围并且有效。