+ Reply to Thread
Results 1 to 6 of 6

msg Box Value to be Saved File Name ??

  1. #1
    Corey
    Guest

    msg Box Value to be Saved File Name ??

    It the below msg box i want the value that is entered INTO the msg box to
    NAME the file to Save. (eg. File 10)

    Sub Macro20()
    Range("A4").Select
    Selection.ClearContents

    res = InputBox("The MAXIMUM number of Sheets have been reached,
    This is a NEW COPY of the WorkBook.", "Company Name ....")

    If res = "" Then Exit Sub
    ActiveWindow.DisplayWorkbookTabs = False
    With ActiveWindow
    .DisplayHorizontalScrollBar = False
    .DisplayVerticalScrollBar = False
    End With

    End Sub



    What step needs to added to madify this so it will name it this?

    Corey....



  2. #2
    NickHK
    Guest

    Re: msg Box Value to be Saved File Name ??

    Corey,
    I guess you have to answer the user a question:
    res = InputBox("What is the name of the file ?", "Company Name ....")
    ThisWorkbook.SaveAs res
    - with error handling added
    But you also pop up the SaveAs dialog, that's its purpose:
    Application.dialogs(xlDialogsaveAs).show

    NickHK

    "Corey" <[email protected]> wrote in message
    news:[email protected]...
    > It the below msg box i want the value that is entered INTO the msg box to
    > NAME the file to Save. (eg. File 10)
    >
    > Sub Macro20()
    > Range("A4").Select
    > Selection.ClearContents
    >
    > res = InputBox("The MAXIMUM number of Sheets have been reached,
    > This is a NEW COPY of the WorkBook.", "Company Name ....")
    >
    > If res = "" Then Exit Sub
    > ActiveWindow.DisplayWorkbookTabs = False
    > With ActiveWindow
    > .DisplayHorizontalScrollBar = False
    > .DisplayVerticalScrollBar = False
    > End With
    >
    > End Sub
    >
    >
    >
    > What step needs to added to madify this so it will name it this?
    >
    > Corey....
    >
    >




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Corey,

    Windows will only rename a closed file. Once you have done that you can use the 'Name... As...' statement to rename the workbook. The macro would have to be run from the original workbook since you need to close the copy.

    Name As Statement Example:
    Name <old path name> As <new path name>

    Path name can also include the Drive and Folder(s).
    The New path name doesn't have to be on the same drive or in the same directory as the old path name.

    Sincerely,
    Leith Ross

  4. #4
    Corey
    Guest

    Re: msg Box Value to be Saved File Name ??


    Thanks for the reply Nick.
    Your comments clear up my untrained mind about an Input and a msg boxes.

    One thing i found is that the below code SavesAs. the current file opened
    and NOT the file that is is copying.

    What can i change in the: ThisWorkbook.SaveAs res string
    to to refer to the NEW file instead?

    Corey....


    "NickHK" <[email protected]> wrote in message
    news:[email protected]...
    > Corey,
    > I guess you have to answer the user a question:
    > res = InputBox("What is the name of the file ?", "Company Name ....")
    > ThisWorkbook.SaveAs res
    > - with error handling added
    > But you also pop up the SaveAs dialog, that's its purpose:
    > Application.dialogs(xlDialogsaveAs).show
    >
    > NickHK
    >
    > "Corey" <[email protected]> wrote in message
    > news:[email protected]...
    >> It the below msg box i want the value that is entered INTO the msg box to
    >> NAME the file to Save. (eg. File 10)
    >>
    >> Sub Macro20()
    >> Range("A4").Select
    >> Selection.ClearContents
    >>
    >> res = InputBox("The MAXIMUM number of Sheets have been reached,
    >> This is a NEW COPY of the WorkBook.", "Company Name ....")
    >>
    >> If res = "" Then Exit Sub
    >> ActiveWindow.DisplayWorkbookTabs = False
    >> With ActiveWindow
    >> .DisplayHorizontalScrollBar = False
    >> .DisplayVerticalScrollBar = False
    >> End With
    >>
    >> End Sub
    >>
    >>
    >>
    >> What step needs to added to madify this so it will name it this?
    >>
    >> Corey....
    >>
    >>

    >
    >




  5. #5
    Corey
    Guest

    Re: msg Box Value to be Saved File Name ??

    Thanks for the reply Leith.

    My post above your post explains what i am after a bit further.

    I have just realised also that, IF i click the CANCEL in the Input box, i
    get an error AND the NEW WorkBook is STILL created.

    res = InputBox("The MAXIMUM No. of Records is reached, NAME NEW File AS ? ",
    "Company Name...")
    ThisWorkbook.SaveAs res
    If res = "" Then Exit Sub <=============
    Does this not stop the macro if CANCEL or nothing is entered ?
    Application.Dialogs(xlDialogSaveAs).Show <============= Want this to SAVE
    NEW FILE NOT old file....
    ActiveWindow.DisplayWorkbookTabs = True
    With ActiveWindow
    .DisplayHorizontalScrollBar = True
    .DisplayVerticalScrollBar = False
    End With

    End Sub


    Corey.....



  6. #6
    Chip Pearson
    Guest

    Re: msg Box Value to be Saved File Name ??

    The order of your commands is wrong. Rather than

    res = InputBox("The MAXIMUM No. of Records is reached, NAME NEW
    File AS ? ", _
    "Company Name...")
    ThisWorkbook.SaveAs res
    If res = "" Then Exit Sub

    you need
    res = InputBox("The MAXIMUM No. of Records is reached, NAME NEW
    File AS ? ", _
    "Company Name...")
    If res = "" Then Exit Sub
    ThisWorkbook.SaveAs res


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com



    "Corey" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks for the reply Leith.
    >
    > My post above your post explains what i am after a bit further.
    >
    > I have just realised also that, IF i click the CANCEL in the
    > Input box, i get an error AND the NEW WorkBook is STILL
    > created.
    >
    > res = InputBox("The MAXIMUM No. of Records is reached, NAME NEW
    > File AS ? ", "Company Name...")
    > ThisWorkbook.SaveAs res
    > If res = "" Then Exit Sub
    > <============= Does this not stop the macro if CANCEL or
    > nothing is entered ?
    > Application.Dialogs(xlDialogSaveAs).Show <============= Want
    > this to SAVE NEW FILE NOT old file....
    > ActiveWindow.DisplayWorkbookTabs = True
    > With ActiveWindow
    > .DisplayHorizontalScrollBar = True
    > .DisplayVerticalScrollBar = False
    > End With
    >
    > End Sub
    >
    >
    > Corey.....
    >




+ 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