D
Daan
Hi!
I recorded a macro in Excel, downloading a range of data from our SQLserver.
I now want to change the date and timestamp I entered in the macro to a value
that a user types in a cell in Excel.
This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) & "WHERE
(POM_Machinedata.DATUM_AKTUELL>={ts '2005-07-13 13:25:38'} And POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) & "" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.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
End Sub
Now I want to change the date '2005-07-13 13:25:38' to a cell name, for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to the date
in cell A2.
By simply replacing the date by the cell name, I run into problems in the
last line (.Refresh BackgroundQuery:=False).
Any help is welcome!
Have a nice weekend,
Daan
I recorded a macro in Excel, downloading a range of data from our SQLserver.
I now want to change the date and timestamp I entered in the macro to a value
that a user types in a cell in Excel.
This is the VBA code:
Sub Import()
'
' Import Macro
' Macro recorded 23.09.2005 by Daan'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=SQL04;UID=Daan;APP=Microsoft Office
2003;WSID=####;DATABASE=###;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT POM_Machinedata.DATUM_AKTUELL,
POM_Machinedata.TOWEINSATZGEWICHT" & Chr(13) & "" & Chr(10) & "FROM
POM.dbo.POM_Machinedata POM_Machinedata" & Chr(13) & "" & Chr(10) & "WHERE
(POM_Machinedata.DATUM_AKTUELL>={ts '2005-07-13 13:25:38'} And POM_Machined" _
, _
"ata.DATUM_AKTUELL<={ts '2005-09-22 10:59:53'})" & Chr(13) & "" &
Chr(10) & "ORDER BY POM_Machinedata.DATUM_AKTUELL" _
)
.Name = "Query from SQL04"
.FieldNames = True
.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
End Sub
Now I want to change the date '2005-07-13 13:25:38' to a cell name, for
example to the date in cell A1 and the date '2005-09-22 10:59:53' to the date
in cell A2.
By simply replacing the date by the cell name, I run into problems in the
last line (.Refresh BackgroundQuery:=False).
Any help is welcome!
Have a nice weekend,
Daan