Running an Excel macro from Access problem

H

Huff

Hi

I'm trying to run the following code in an Access function in order to
run an Excel macro. The problem I have is that I wish to close the
excel workbook but with changes saved. If I add in the line
'objExcel.Save' before the close command it throws errors saving do you
want to replace 'resume.xla'. 'objExcel.Workbooks.Save' doesn't seem to
work either.

How can I get the workbook to close with changes saved?

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open ("C:\[file path and name here].xls")
objExcel.Visible = True
objExcel.Run "Update"
objExcel.Workbooks.Close
objExcel.Quit

Thanks in advance!

Doug
 
D

Dave Peterson

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook _
= objExcel.Workbooks.Open ("C:\[file path and name here].xls")
objExcel.Visible = True
objExcel.Run "Update"
objWorkbook.close True 'savechanges:=true
set objExcel = nothing
Set objWorkbook = nothing
objExcel.Quit
Hi

I'm trying to run the following code in an Access function in order to
run an Excel macro. The problem I have is that I wish to close the
excel workbook but with changes saved. If I add in the line
'objExcel.Save' before the close command it throws errors saving do you
want to replace 'resume.xla'. 'objExcel.Workbooks.Save' doesn't seem to
work either.

How can I get the workbook to close with changes saved?

Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open ("C:\[file path and name here].xls")
objExcel.Visible = True
objExcel.Run "Update"
objExcel.Workbooks.Close
objExcel.Quit

Thanks in advance!

Doug
 
H

Huff

Thanks Dave, worked a treat.

Had to remove the final objExcel.Quit line, 'cos we'd already set
objExcel to Nothing in the previous line, but after that it's all
systems go again.

Cheers.


Dave Peterson wrote:
 
D

Dave Peterson

I think you may have wanted to rearrange those commands so that the .quit was
before the "set = nothing" line.
 

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