+ Reply to Thread
Results 1 to 4 of 4

Running an Excel macro from Access problem

  1. #1
    Huff
    Guest

    Running an Excel macro from Access problem

    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


  2. #2
    Dave Peterson
    Guest

    Re: Running an Excel macro from Access problem

    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

    Huff wrote:
    >
    > 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


    --

    Dave Peterson

  3. #3
    Huff
    Guest

    Re: Running an Excel macro from Access problem

    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:


  4. #4
    Dave Peterson
    Guest

    Re: Running an Excel macro from Access problem

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



    Huff wrote:
    >
    > 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:


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1