Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Close a Workbook within a macro How?

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Cambridge England
    Posts
    521
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    In the following code example
    I am saving a workbook in directory Q:NEWQUOTESYSTEMQUOTES then taking information from three cells to produce the filename. As it stands the workbook is saved OK but then remains open even though I have opened another workbook in the macro. I want to save the workbook and then close the workbook ignoring any save as prompts etc.
    Thanks Ted


    Sub CopySheetSave()
    '
    ' CopySheetSave Macro
    ' Macro recorded 03/03/2002 by Ted Pratt
    '
    'Save the quote
    ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

    'This is where I want to close the above workbook


    'After the save open mster sheet
    Workbooks.Open Filename:="Q:NEWQUOTESYSTEMMasterQuoteSheet2.xls"

    End Sub

  2. #2
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-23 13:20, eddy wrote:
    In the following code example
    I am saving a workbook in directory Q:NEWQUOTESYSTEMQUOTES then taking information from three cells to produce the filename. As it stands the workbook is saved OK but then remains open even though I have opened another workbook in the macro. I want to save the workbook and then close the workbook ignoring any save as prompts etc.
    Thanks Ted


    Sub CopySheetSave()
    '
    ' CopySheetSave Macro
    ' Macro recorded 03/03/2002 by Ted Pratt
    '
    'Save the quote
    ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

    'This is where I want to close the above workbook


    'After the save open mster sheet
    Workbooks.Open Filename:="Q:NEWQUOTESYSTEMMasterQuoteSheet2.xls"

    End Sub
    Either put

    ActiveWorkbook.Close

    where you indicated it should go.

    Or change the line

    ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

    to

    ActiveWorkbook.Close SaveChanges:=True, Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value


    HTH,
    Jay

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cambridge England
    Posts
    521
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Works fine.
    Thanks Jay

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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