SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Anything wrong with the codes?

Reply
Contributor
Posts: 49

Anything wrong with the codes?

Hi,

I'm trying to read a sas dataset using vba. Below is my codes. But it seems something wrong with my codes or some problems with my seeting.   "Error 424" always pops up. Anyone could help me out?

Thanks in advance.

Public Sub GetData()

Dim obConnection As Object

Dim obRecordset As Object

Dim i As Integer

Set obConnection = CreateObject("Adodb.Connection")

Set obRecordset = CreateObject("ADODB.Recordset")

obConnection.Provider = "sas.LocalProvider.1"

obConnection.Properties("Data Source") = "D:\Project\"

obConnection.Open

obRecordset.Open "raw", obConnection, adOpenStatic, adLockReadOnly, ADODB.adCmdTableDirect

'obRecordset.Open "select * from raw", obConnection, adOpenStatic, adLockReadOnly, ADODB.adCmdTableDirect

Range(Cells(1, 1), Cells(obRecordset.RecordCount + 1, obRecordset.Fields.Count)).NumberFormat = "@"

Cells(1, 1).Select

For i = 0 To obRecordset.Fields.Count - 1

       ActiveCell.Offset(0, i).Value = obRecordset.Fields(i).Name

  Next i

Set obConnection = Nothing

Set obRecordset = Nothing

End Sub

Ask a Question
Discussion stats
  • 0 replies
  • 230 views
  • 0 likes
  • 1 in conversation