Hi Thread,
Rather than thinking "click the command button", you will
launch the code that the command button runs
Here is code for running a sub from another workbook -- if
the procedure is in the workbook that is open, make the
appropriate substitutions
'~~~~~~~~~~~~~~~~
'--------------- dimension variables
'this is for early binding
'if you need to do late binding,
'do this for developing
'but compile and run with late binding
'Dim xlApp As Excel.Application
'Dim xlWB as Excel.Workbook, xlWBprg as Excel.Workbook
'this is for late binding
Dim xlApp As Object
Dim xlWB as Object, xlWBprg as Object
Dim mExcelFile as string, mPath as string
Dim booCloseExcel as boolean
'--------------- assign variables
booCloseExcel = false
'or whatever is the path
mPath = CurrentProject.Path & "\"
mExcelFile = "Whatever.xls"
'--------------- set Excel object
'if Excel is already open, use that instance
booCloseExcel = false
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
On Error GoTo error_handler
'What did we find?...
If TypeName(xlApp) = "Nothing" Then
'Excel was not open -- create a new instance
Set xlApp = CreateObject("Excel.Application")
booCloseExcel = true
End If
'comment out after your program is done (if you want to!)
xlApp.Visible = True
'---------------
' ...more statements
'--------------- open workbook with the code
'if applicable
set xlWBprg = xlApp.Workbooks.Open( _
mPath & "PROGRAMS.XLS")
'--------------- open workbook to run code on
set xlWB = xlApp.Workbooks.Open( _
mExcelFile)
'--------------- run Sub in Programs Workbook
xlApp.Run "PROGRAMS.XLS!ModuleName.SubName"
'--------------- save Workbook
xlWB.save
'--------------- close Workbooks
xlWb.Close False
xlWbprg.Close False
'--------------- close Excel
'xlApp.Visible = False
If booCloseExcel = true then
xlApp.quit
end if
'--------------- release object variables
set xlWB = nothing
set xlWBprg = nothing
set xlApp = nothing
'~~~~~~~~~~~~~~~~
Warm Regards,
Crystal
Microsoft Access MVP 2006
*
Have an awesome day
remote programming and training
strive4peace2006 at yahoo.com
*