Excel - ERROR 1004 VBA, al combiar un valor en una celda, (macro con ODBC)
Publicado por Kevin Fernández (2 intervenciones) el 20/05/2015 20:10:35
hola, estoy tratando de sacar informacion a excel a traves de ODBC. la macro corria normal, pero necesitaba que la funcion capturara el valor de una celda y la utilizara como filtro en la consulta, entonces declare una variable "x", le asigne el valor que necesitaba que se encuentra en la celda F3 y luego la mande como parametro en "set @year = x", a continuacion dejo mi codigo
ayuda por favor
ayuda por favor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Dim x As Integer
x= Range("F3").Value
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=alone", _
Destination:=Range("$B$5")).QueryTable
.CommandText = Array( _
"declare @year integer set @year = x SELECT DISTINCT CFI.NUM_CFI, CFI.FEC_EMI , CFI.FEC_VTO , MOV.NUM_LIQ , CFI.MON_CFI , MOV.MON_TOT_GAS FROM CRE$CFI CFI, CRE$MOV MOV" _
, _
" WHERE ( YEAR(CFI.FEC_EMI) <= @year and YEAR(CFI.FEC_VTO) >= @year) AND IND_VIG_CFI IN ('3', '5') AND MOV.NUM_CTA = CFI.NUM_CFI AND MOV.IND_MOV_EXT = 0 AND MOV.COD_MOV = '0" _
, "38' ORDER BY CFI.FEC_VTO, CFI.FEC_EMI")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Valora esta pregunta


0