+ Reply to Thread
Results 1 to 5 of 5

Macro to prompt user to select a file and the selected file should saved in location

  1. #1
    Registered User
    Join Date
    06-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003 and Excel 2007
    Posts
    11

    Macro to prompt user to select a file and the selected file should saved in location

    Hi,

    I'm trying to write a code which will prompt user to select a file and the selected file should get saved in the location specified in cell A1 in the master file (note i'll be running macro from the master file). When i run the below code i'm getting an error message stating object required.

    Sub Test()

    'path specified in master file
    Dim a As String
    a = Cells(1, 1).Value

    'prompt the user to select a file

    Dim filename

    filename = Application.GetOpenFilename

    'upon selecting file, it should get saved in the path specified in A1 cell in master file
    If filename <> False Then
    filename.SaveAs "a"


    End If
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro to prompt user to select a file and the selected file should saved in location

    Hi Logesh,

    I like the Application.FindFile to pick and open my files.

    Then after it is open save the filename and path for later use using
    Application.Path and/or Activeworkbook.Name
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    06-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003 and Excel 2007
    Posts
    11

    Re: Macro to prompt user to select a file and the selected file should saved in location

    Thanks Marvin! I appreciate your response. In my scenario i shouldn't open the file but the macro should allow me to choose a file and the selected file should get saved in the path specified in A1.

    Example - i run a macro from Book1 and the macro should prompt me to select a file and the selected file should get saved in the location mentioned in Book1 A1 cell.

    Thanks again.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro to prompt user to select a file and the selected file should saved in location

    Hi logesh,

    Open the attached and change the path in cell A1 to somewhere on your drives that you want to save files. Then run the macro and see what happens.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003 and Excel 2007
    Posts
    11

    Re: Macro to prompt user to select a file and the selected file should saved in location

    Hi Marvin,

    I appreciate your response. The code that you have suggested saves the selected file as it is rather than the location specificed in the A1. Now I have figured out a method.

    Sub SaveFilesInA1()

    Dim Path As String

    Path = Workbooks("Book1").Worksheets("Sheet1").Range("A1")
    Application.FindFile
    ActiveWorkbook.SaveAs Path & ActiveWorkbook.Name
    ActiveWorkbook.Close
    End Sub

+ 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] How to prompt user to select file to attach to an E-Mail (Excel to Outlook)
    By TheLittlePrince in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 05:33 AM
  2. [SOLVED] Macro to prompt user to select date and save file
    By TheLittlePrince in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2013, 08:34 AM
  3. Macro to prompt user for file name and save in location
    By Fungijus in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-21-2011, 02:16 PM
  4. How to prompt user for location of file to reference
    By SymphonyTomorrow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2010, 01:23 AM
  5. Prompt user to select file to import
    By Lmsloman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-19-2009, 07:23 PM

Tags for this Thread

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