Option Compare Database
Option Explicit
Sub OpenExcel()
Dim objExcelApp As New Excel.Application
Dim objExcel As Object
'create Excel
Set objExcelApp = New Excel.Application
'open file
Set objExcel = objExcelApp.Workbooks.Open("D:\booknew.xls"
'make it visible if you want
objExcelApp.Visible = True
call objExcel.SubName
Set objExcel = Nothing 'clears memory
set objExcelApp = nothing
end sub
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
When I try to run this code I'm getting this error-msg : "user-defined type not defined" on "Dim objExcelApp As New Excel.Application"
Depends what the macro does - if it selects sheets and the like, excel will need to have the focus
What's the error and what line did it "crash" on ??
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
I do apologise - having tried this again, it would appear not to work on XP
try this instead:
Option Compare Database
Option Explicit
Sub OpenExcel()
Dim objExcelApp As New Excel.Application
Dim objExcel As Object
'create Excel
Set objExcelApp = New Excel.Application
'open file
Set objExcel = objExcelApp.Workbooks.Open("D:\booknew.xls"
'make it visible if you want
objExcelApp.Visible = True objExcelApp.Run "SubName"
Set objExcel = Nothing 'clears memory
set objExcelApp = nothing
end sub
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.