Guys, I am new to Excel VBA and desperately in need of help.
I do not know if it is possible to do in Excel/VBA but this is what I want to do.
"Create a template in excel for users with sales data with subtotals for a week, month etc.I want them to just open the file where it refreshes/connects to the database (SQL Server)behind the scenes, retrieves data through a query, loops thorugh the data and throws it into appropriate cells in the spreadsheets and create hyperlinks from each and every number/data(sales figure). On clicking the hyperlink/sales figure a small window pops up giving the detailed information (drill down) about the number.
1. Can some one tell me if that is possible.
2. what am I doing wrong in this script that it gives me "Compile Error: User Defined Type not defined." for "Set db_data = New Connection" in the following code:
Sub Aut
pen()
Set db_data = New Connection
db_data.CursorLocation = adUseClient
db_data.Open "PROVIDER=MSDASQL;dsn=SQLConn;uid=sa;pwd=sa;database=PSTEST;"
Set ado_data = New Recordset
' Assume we retrieve two columns of data that are to go into column A and B respectively
' of the spreadsheet
ado_data.Open "select * from PSTEST.dbo.PS_AHP_CORP_SUM_VW", adOpenStatic, adLockOptimistic
If ado_data.RecordCount <= 0 Then
MsgBox ("No data found")
End Sub
End If
ado_data.movefirst
For I = 0 To ado_data.RecordCount - 1
Book1.Cells(I + 1, 1) = (ado_data.Fields.Item(0).Value)
Book1.Cells(I + 1, 2) = (ado_data.Fields.Item(1).Value)
ado_data.MoveNext
Next
End Sub
I do not know if it is possible to do in Excel/VBA but this is what I want to do.
"Create a template in excel for users with sales data with subtotals for a week, month etc.I want them to just open the file where it refreshes/connects to the database (SQL Server)behind the scenes, retrieves data through a query, loops thorugh the data and throws it into appropriate cells in the spreadsheets and create hyperlinks from each and every number/data(sales figure). On clicking the hyperlink/sales figure a small window pops up giving the detailed information (drill down) about the number.
1. Can some one tell me if that is possible.
2. what am I doing wrong in this script that it gives me "Compile Error: User Defined Type not defined." for "Set db_data = New Connection" in the following code:
Sub Aut
Set db_data = New Connection
db_data.CursorLocation = adUseClient
db_data.Open "PROVIDER=MSDASQL;dsn=SQLConn;uid=sa;pwd=sa;database=PSTEST;"
Set ado_data = New Recordset
' Assume we retrieve two columns of data that are to go into column A and B respectively
' of the spreadsheet
ado_data.Open "select * from PSTEST.dbo.PS_AHP_CORP_SUM_VW", adOpenStatic, adLockOptimistic
If ado_data.RecordCount <= 0 Then
MsgBox ("No data found")
End Sub
End If
ado_data.movefirst
For I = 0 To ado_data.RecordCount - 1
Book1.Cells(I + 1, 1) = (ado_data.Fields.Item(0).Value)
Book1.Cells(I + 1, 2) = (ado_data.Fields.Item(1).Value)
ado_data.MoveNext
Next
End Sub