当前位置: 代码迷 >> VBA >> VBA 高手请止步解决方法
  详细解决方案

VBA 高手请止步解决方法

热度:10054   发布时间:2013-02-26 00:00:00.0
VBA 高手请止步
With ActiveWorkbook.PivotCaches.create(SourceType:=xlExternal, Version:= _
  xlPivotTableVersion12)
  .Connection = DataSQLConnectionString '"OLEDB;Provider=MSDAORA.1;User ID=circstat;Data Source=tjdb"
  .CommandType = xlCmdSql
  .CommandText = select 产品,月份,数量,
case 
  when 数量 <= '10 ' and 数量 > '0 ' then
  '0-10'
  when 数量 <= '20 ' and 数量 > '10 ' then
  '10-20'
  when 数量 <= '10000 ' and 数量 > '20 ' then
  '20-10000'
  end 保额区间 from VW_ORDER33 where 1=1 and 月份 in ('2008-01','2008-02','2008-03','2008-04') and 产品 = 'MP3' and 月份 = '2008-01'
  .MaintainConnection = True
  .CreatePivotTable TableDestination:=Sheet1.Cells(6, 6), TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion12
  End With

有错误吗?

------解决方案--------------------------------------------------------
首先,你这个 .CommandText = 赋值的怎么不是字符串啊?建议把后面属于它的字符串全部使用双引号引起来。如果非要换行,建议使用下面的方法:

VBScript code
.CommandText = "第一行" _"第二行"
  相关解决方案