Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSAccess opening an excel file (*.xls)

Status
Not open for further replies.

hockeyboi16

Programmer
Aug 8, 2006
18
US
How do i open a pre-existing excel file (*.xls) using VBA in microsoft Access?

When i try to use

dim workbook as Excel.Workbook

i am getting an error, so i therefore cannot use any of the code i have found on the web. Any suggestions?

Any help is much appreciated! Thanks in advance

--whit
 
Dim oWB As Object
Set oWB = GetObject("\path\to\file.xls")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmm, once i do this, what do i do?

I appreciate you helping me out!

--whit
 
what do i do
You now have a valid Excel.Workbook object.
Examples:
oWB.Application.Visible = True
oWB.SaveAs "\path\to\newfile.xls"
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Okay, i have another question...

i did this, and the application.visible = true, and it opens up Excel. The only thing is, i'm doing this in a sub, and once i put the application to visible= true, it goes to "end sub" and excel is exited. How can i make this stay open so the user can edit the file in excel?

--whit
 
Sub yourProcedure()
Dim oXL As Object
Set oXL = CreateObject("Excel.Application")
oXL.Workbooks.Open "\path\to\file.xls"
oXL.Visible = True
Set XL = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about the FollowHyperlink method?

And if you are going to create an instance of Excel, you should probably check if one is open already (IMHO).

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top