lifeisanart
02-01-2016, 06:55 AM
Dear All,
How are you doing?
I want to import the data from the sql query to excel through vba. But I tried my code and turned out a totally blank of the sheet I want to see.
Here is code, could you please help to have a look for me since I have no clue after many corrections and test.
thanks very much.
Private Function GetFromDatabase(ByVal sSQL As String, ByVal sCell As String) As Boolean
On Error GoTo err_handler
Dim v As Variant
v = Application.Run("ExecuteQuery", sSQL)
Application.Run "CopytoExcel", v, sCell
GetFromDatabase = True
Exit Function
err_handler:
GetFromDatabase = False
End Function
Sub FullRefreshfromDatabase()
GetMainfromDatabase
GetMaturityfromDatabase
End Sub
Sub GetMaturityfromDatabase()
Sheets("raw_data").Columns("A:CZ").ClearContents
GetFromDatabase "exec qMaturity", "raw_data!A1"
End Sub
Sub GetMainfromDatabase()
Sheet2.Cells.Copy Destination:=Sheet1.Cells
End Sub
How are you doing?
I want to import the data from the sql query to excel through vba. But I tried my code and turned out a totally blank of the sheet I want to see.
Here is code, could you please help to have a look for me since I have no clue after many corrections and test.
thanks very much.
Private Function GetFromDatabase(ByVal sSQL As String, ByVal sCell As String) As Boolean
On Error GoTo err_handler
Dim v As Variant
v = Application.Run("ExecuteQuery", sSQL)
Application.Run "CopytoExcel", v, sCell
GetFromDatabase = True
Exit Function
err_handler:
GetFromDatabase = False
End Function
Sub FullRefreshfromDatabase()
GetMainfromDatabase
GetMaturityfromDatabase
End Sub
Sub GetMaturityfromDatabase()
Sheets("raw_data").Columns("A:CZ").ClearContents
GetFromDatabase "exec qMaturity", "raw_data!A1"
End Sub
Sub GetMainfromDatabase()
Sheet2.Cells.Copy Destination:=Sheet1.Cells
End Sub