Results 1 to 2 of 2

Thread: workbooks(1).saveas for the second time

  1. #1
    Board Regular
    Join Date
    Mar 2016
    Posts
    1,148
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default workbooks(1).saveas for the second time

    Hi
    When I run the code below for the first time, I get no error message and file name would change to testing123.xlsx but when I run it for the second time, I get error message saying the file already existed. How can I change that or can I? Thank you very much.

    Code:
    Sub savewb()
      Workbooks(2).SaveAs Filename:="testing123.xlsx"
    End Sub

  2. #2
    Board Regular
    Join Date
    Jul 2007
    Location
    Sydney
    Posts
    4,224
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Default Re: workbooks(1).saveas for the second time

    Hi lezawang,

    If you want to save over an existing file no questions asked (I think that's what you're asking), try this:

    Code:
    Sub savewb()
        Application.DisplayAlerts = False
            Workbooks(2).SaveAs Filename:="testing123.xlsx"
        Application.DisplayAlerts = True
    End Sub
    Regards,

    Robert

Some videos you may like

User Tag List

Tags for this Thread

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
  •