LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default Run Excel VBA code inside Access

Hans,
This ought to get you closer. I am not sure if Access is going to know
what to do with "What" and "Replacement". You may have to use
the values without the argument names...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Private Sub Command4_Click()
DoCmd.RunSQL "Delete * From CAEmployees"
Dim objXL As Object
Dim objWB As Object
Dim objSht As Object
Dim LastRow As Long
'On Error Resume Next
Set objXL = CreateObject("Excel.Application")
objXL.Application.Visible = True
Set objWB = objXL.Application.Workbooks.Open("C:\Documents and " & _
"Settings\Administrator\My Documents\N Conner Employee List.XLS")
Set objSht = objWB.Sheets("emplistwithbydiv")
LastRow = objSht.Cells(objSht.Rows.Count, "A").End(xlUp).Row
objSht.Range("T2:T" & LastRow).Replace What:="F", Replacement:=""
objSht.Range("T2:T" & LastRow).Replace What:="S", Replacement:=""
objSht.Range("T2:T" & LastRow).Replace What:="P", Replacement:=""
objSht.Range("R2:W" & LastRow, "O2" & LastRow, "N2" & LastRow, "A2:E" & _
LastRow).NumberFormat = "0"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "CAEmployees", "N Conner Employee List.xls", -1
DoCmd.RunSQL "update CAEmployees set[Name]=[Nick Name]&' '&[Last Name]"
End Sub
'-------------




wrote in message
I can get the code to open the correct wkbk, but cannot get it to
execute the excel, what I call "cleanup" portion. The replace
section....It just does nothing, anybody know why?

Private Sub Command4_Click()
DoCmd.RunSQL "Delete * From CAEmployees"
Dim objXL As Object
Dim Sheets As Object
On Error Resume Next
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
.Workbooks.Open "C:\Documents and Settings\Administrator\My
Documents\N Conner Employee List.XLS"
NConnerEmployeeList.xls.Activate
Sheets("emplistwithbydiv").Select
Dim LastRow As Long
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range("T2:T" & LastRow)
Cells.Replace What:="F", Replacement:=""
Cells.Replace What:="S", Replacement:=""
Cells.Replace What:="P", Replacement:=""
End With
With .Range("R2:W" & LastRow, "O2" & LastRow, "N2" & LastRow,
"A2:E" & LastRow)
.NumberFormat = "0"
End With
End With
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"CAEmployees", "N Conner Employee List.xls", -1
DoCmd.RunSQL "update CAEmployees set[Name]=[Nick Name]&' '&[Last Name]"
End Sub
THKS,
Hans

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
Using Access in Excel VB Code Michael Excel Discussion (Misc queries) 1 February 2nd 06 07:31 PM
Data from Excel to Access Table Secret Squirrel Excel Discussion (Misc queries) 11 December 2nd 05 11:58 PM
Excel and Access talking GJR3599 Excel Discussion (Misc queries) 0 March 29th 05 04:59 PM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"