Opening an Excel workbook or template directly from within Access

C

Colin Foster

Hello,
Don't know if this is the best Group to post this query to. If not, could
someone point me in the right direction. Thanks.
OK, down to business...
I want to be able to do two things...
1. Open a specific XL (and Word) template from within access by placing a
button on my form. I can do the straightforward Open XL, but need a specific
template...any suggestions?
2. I also need to be able to open a specific file (using either XL or Word.
I've found the KB article 325234: HOW TO: Start Another Application from a
Text Box on a Form which appears to give me exactly what I want...BUT (why
is there always a but??) when I set up my form as suggested within the KB
Article, the Text Box txtAppPath shows #Name? which makes me think that I've
set it up incorrectly... Following the KB article, I set the control source
to :c\program files (etc) but I'm beginning to wonder whether this is
correct.
Any help would be appreciated
Regards
Colin Foster
 
C

Chad

Kinda hard to follow your question but here's an answer, I
hope it applies.

Create a reference (go into any module, click tools,
references and set a reference to Excel).
In your button's on click add:
Dim oExcel As New Excel.Application
Dim oSheet As Worksheet
Dim oWorkbook As New Workbook
Set oExcel = CreateObject("Excel.Application")
Set oWorkbook = oExcel.Workbooks.Open
(Me.Textboxwiththefilename)
Set oSheet = oWorkbook.Sheets(1)
oExcel.Visible=True

Then you can do all sorts of magic with osheet, oworkbook,
oexcel. If you only need to open the excel file and don't
need to do anything special to it, just use this in your
command button's on click:
Dim objWSH As Object
Set objWSH = CreateObject("WScript.Shell")
Call objWSH.Run(Chr(34) & Me.textboxwiththefilename & Chr
(34))
Set objWSH = Nothing

in both cases, you'd need to insert the correct textbox
name. You may also want to check to see if the file even
exists before opening it... and so on.


To open a specific template I'm not certain as I've never
really done it but I suspect you can just open the
template and it will use excel to open it. Use the second
example and instead of the me.textboxwiththefilename
use "c:\pathtotemplate\templatefile"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top