+ Reply to Thread
Results 1 to 4 of 4

save and close named workbook

  1. #1
    Registered User
    Join Date
    01-04-2012
    Location
    luton
    MS-Off Ver
    Excel 2010
    Posts
    3

    save and close named workbook

    Hi
    I have sveral workbooks open and i just want to save and close a particular one. From google searches i see this is straightforward if you use the same script to first open the file but i just want to save and close without opening and leave all other workbooks running. I wonder if the code below just needs the Set objWorkbook reference set to a named running workbook? Not sure how to do that and everything i tried just gives an error. Thanks for any help.


    set objExcel = SetObject("Excel.Application")
    objExcel.Visible = True
    objExcel.DisplayAlerts = FALSE

    Set objWorkbook = objExcel.Workbooks.Open ("c:\test\database.xlsx")

    objWorkbook.SaveAs("c:\test\database.xlsx")
    objExcel.Quit

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: save and close named workbook

    You don't really need an object if the workbook is already open
    Please Login or Register  to view this content.
    Just make sure the workbooks name is spelled correctly. Its case sensitive.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    01-04-2012
    Location
    luton
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: save and close named workbook

    Hi, thanks but i get the error "expected statement"
    i literally just run the line you posted.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: save and close named workbook

    It needs to be wrapped in a procedure. If this is to be used by itself with no other code:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. MAC VBA Fails to save and close named workbook
    By codebasher in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 5
    Last Post: 01-07-2014, 10:21 AM
  2. How to open,save and close another workbook from the current workbook using macro?
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2012, 10:42 AM
  3. Save and close a workbook using VBA
    By Kimberly123 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-23-2012, 09:33 AM
  4. Close workbook and save as.
    By Hjahren in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-13-2010, 04:41 AM
  5. Help on Workbook close and workbook save events
    By Adam Harding in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2005, 12:05 PM

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