+ Reply to Thread
Results 1 to 5 of 5

Saving a file to specific location using a command button

  1. #1
    Registered User
    Join Date
    08-22-2019
    Location
    UK
    MS-Off Ver
    Excel- 2013
    Posts
    18

    Saving a file to specific location using a command button

    Hi All.

    There is a process we do at work which requires to save an excel file to a specific folder (must do it 150 to 200 times each month).
    I thought it might be useful to use the command button to save it to that folder and close it rather than going through file/saveas/folder etc etc.
    When saving I thought it may be useful to use the text in say Cell "C4" as file name so it appears with that name in the folder if need to look for it.
    I tried the bottom two macros but had 2 problems 1) the location it saved in was the master folder in this case "Adhoc" not the subfolder 2) filename wasn't what was in the Cell "C4".
    Hope that makes sense

    Macro 1)
    Private Sub CommandButton1_Click()

    Dim path As String
    Dim filename As String

    path = "C:\Users\R****************\Desktop\Adhoc\Subfolder"
    filename = Range("C4").Text
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs filmename11:= path & filename".xlsx", FileFormat:=xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close

    End Sub

    Macro 2)
    Private Sub CommandButton1_Click()
    Dim MyFile As String

    MyFile = ActiveWorkbook.Name
    'Do not display message about overwriting the existing file.
    Application.DisplayAlerts = False
    ' Save the active workbook with the name of the
    ' active workbook. Save it on the C drive to a folder called
    ' "Users" with a subfolder called "R****************\Desktop\Adhoc\Subfolder."
    ActiveWorkbook.SaveAs filename:="C:\Users\R****************\Desktop\Adhoc\Subfolder" & MyFile
    ' Close the workbook by using the following.
    ActiveWorkbook.Close

    End Sub

    Not too sure where I am going wrong (I am very new to VBAs/Macros too).
    Any help would be much appriciated.

    Thanks in advance

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Saving a file to specific location using a command button

    Add an extra backslash at the end of your path:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Saving a file to specific location using a command button

    @Ram_6833 - please use CODE tag and wrap around VBA code lines (or use # icon on menu)
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  4. #4
    Registered User
    Join Date
    08-22-2019
    Location
    UK
    MS-Off Ver
    Excel- 2013
    Posts
    18

    Re: Saving a file to specific location using a command button

    Quote Originally Posted by WideBoyDixon View Post
    Add an extra backslash at the end of your path:

    Please Login or Register  to view this content.
    WBD
    That worked perfect, simple mistake can crash the whole thing ey, Thank you so much

  5. #5
    Registered User
    Join Date
    08-22-2019
    Location
    UK
    MS-Off Ver
    Excel- 2013
    Posts
    18

    Re: Saving a file to specific location using a command button

    Quote Originally Posted by KOKOSEK View Post
    @Ram_6833 - please use CODE tag and wrap around VBA code lines (or use # icon on menu)
    Sorry I don't quiet get what you mean.

+ 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. [SOLVED] Help with VBA to automate saving file in specific location and file name with dates
    By fornight in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2017, 08:07 AM
  2. Saving a Workbook With A Specific File Name in a Specific Location
    By kyjae in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2016, 02:49 PM
  3. Replies: 0
    Last Post: 09-01-2014, 04:45 PM
  4. [SOLVED] Saving file in a date specific location
    By mayurpatil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2013, 01:30 AM
  5. macro button to attach file to a specific location
    By nicko54 in forum Excel General
    Replies: 0
    Last Post: 06-25-2012, 08:41 PM
  6. VBA command button for saving as date stamped copy in new location (and original)
    By Ogunhe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2012, 10:31 AM
  7. VBA for saving a file to a specific location
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-07-2005, 04: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