J
Jado
hi
i call Excel 97 from Access97 to perform a data export to Excel.
since upgrading to Win2000, if the macro is ran as Administrator, then no
problems..!
when run by a user with only Domain User rights..
the macro still runs but it brings up the DNS Data Source screen...
the user then must select MS Access driver from the list....
and enter 'Admin' in the user name...
if this is done, the Excel sheet is created ok..!
if not, the sheet is still created but with no data attached..!!
----------------------------------------------------------------------------
Function LeadsToExcel(dbPath As String, BasePath As String, qryName As
String, docName As String)
'Exports all daily leads to excel and saves
Dim ojXls As Excel.Application
Dim xlDoc As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim mySQL As String
Dim myCon As String
On Error GoTo Err_Reset
Set ojXls = New Excel.Application
Set xlDoc = ojXls.Workbooks.Add
Set xlSheet = xlDoc.Worksheets.Item(1)
With xlSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access 97 Database;DBQ=" & dbPath & ";" _
), Array( _
"DefaultDir=Path;" _
), Array("DriverId=281;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=xlSheet.Range("A1"))
.SQL = Array( _
"SELECT * " & Chr(13) & "" & Chr(10) & "FROM `" & qryName & "` `" &
qryName & "`")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = False
.Delete
End With
'DeleteExternalDataRange
On Error Resume Next
Kill BasePath & "Path" & docName & ".xls"
ChDir BasePath & "Path"
ojXls.ActiveWorkbook.SaveAs FileName:=BasePath & "Path" & docName &
".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
ChDir "Path"
ojXls.ActiveWorkbook.SaveAs FileName:="Path" & docName & ".xls",
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
xlDoc.Close
ojXls.Quit
Set xlSheet = Nothing
Set xlDoc = Nothing
Set ojXls = Nothing
Exit Function
Err_Reset:
Set xlSheet = Nothing
Set xlDoc = Nothing
Set ojXls = Nothing
MsgBox "Excel Error: " & Err.Number & " - " & Err.Description
End Function
----------------------------------------------------------------------------
i call Excel 97 from Access97 to perform a data export to Excel.
since upgrading to Win2000, if the macro is ran as Administrator, then no
problems..!
when run by a user with only Domain User rights..
the macro still runs but it brings up the DNS Data Source screen...
the user then must select MS Access driver from the list....
and enter 'Admin' in the user name...
if this is done, the Excel sheet is created ok..!
if not, the sheet is still created but with no data attached..!!
----------------------------------------------------------------------------
Function LeadsToExcel(dbPath As String, BasePath As String, qryName As
String, docName As String)
'Exports all daily leads to excel and saves
Dim ojXls As Excel.Application
Dim xlDoc As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim mySQL As String
Dim myCon As String
On Error GoTo Err_Reset
Set ojXls = New Excel.Application
Set xlDoc = ojXls.Workbooks.Add
Set xlSheet = xlDoc.Worksheets.Item(1)
With xlSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access 97 Database;DBQ=" & dbPath & ";" _
), Array( _
"DefaultDir=Path;" _
), Array("DriverId=281;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=xlSheet.Range("A1"))
.SQL = Array( _
"SELECT * " & Chr(13) & "" & Chr(10) & "FROM `" & qryName & "` `" &
qryName & "`")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = False
.Delete
End With
'DeleteExternalDataRange
On Error Resume Next
Kill BasePath & "Path" & docName & ".xls"
ChDir BasePath & "Path"
ojXls.ActiveWorkbook.SaveAs FileName:=BasePath & "Path" & docName &
".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
ChDir "Path"
ojXls.ActiveWorkbook.SaveAs FileName:="Path" & docName & ".xls",
FileFormat:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
xlDoc.Close
ojXls.Quit
Set xlSheet = Nothing
Set xlDoc = Nothing
Set ojXls = Nothing
Exit Function
Err_Reset:
Set xlSheet = Nothing
Set xlDoc = Nothing
Set ojXls = Nothing
MsgBox "Excel Error: " & Err.Number & " - " & Err.Description
End Function
----------------------------------------------------------------------------