+ Reply to Thread
Results 1 to 13 of 13

Macro - Save in same folder

  1. #1
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Macro - Save in same folder

    Hello,

    I need a little bit help here.

    I use a .xls file as Macro file, nothing in there, only macro's.
    So when i need to use any macro, i open that .xls

    After that, i open the other .xls files with data, but that sheets needs to be saved in the same location as opened.

    Is that possible? Because i have tested this code;

    Please Login or Register  to view this content.
    With this code it saves the data .xls files in the folder of the macro .xls
    Can anyone rebuild this code a little bit?


    Thanks,


    - Jessy

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Macro - Save in same folder

    You could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    I don't want to overwrite the old file, it has to save as a new file, with extension .xls. (At the same folder)


    - Jessy

  4. #4
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Macro - Save in same folder

    Quote Originally Posted by Jessy142 View Post
    Hello,

    I need a little bit help here.

    I use a .xls file as Macro file, nothing in there, only macro's.
    So when i need to use any macro, i open that .xls

    After that, i open the other .xls files with data, but that sheets needs to be saved in the same location as opened.

    Is that possible? Because i have tested this code;

    Please Login or Register  to view this content.
    With this code it saves the data .xls files in the folder of the macro .xls
    Can anyone rebuild this code a little bit?


    Thanks,


    - Jessy
    try this one.

    Sub SaveToRelativePath()
    Dim relativePath As String
    Dim sName As String

    sName = "New Name.xlsx"

    relativePath = ThisWorkbook.Path & "\" & sName
    ActiveWorkbook.SaveAs Filename:=relativePath
    End Sub

  5. #5
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    Quote Originally Posted by thisisgerald View Post
    try this one.
    Is it also possible that it saves with same name, but only with new extension (.xls)

  6. #6
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Macro - Save in same folder

    Quote Originally Posted by Jessy142 View Post
    Is it also possible that it saves with same name, but only with new extension (.xls)
    You can remove the last "x" on ".xlsx". I think you cannot save a file with the same name on the same location without overwriting it. Unless what you want is (i.e. File.xls to be named as File1.xls) when saved.

  7. #7
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    Quote Originally Posted by thisisgerald View Post
    You can remove the last "x" on ".xlsx". I think you cannot save a file with the same name on the same location without overwriting it. Unless what you want is (i.e. File.xls to be named as File1.xls) when saved.
    I think its possible because, i can have 2 same file names in one place, but only other extension.

  8. #8
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Macro - Save in same folder

    @jessy142

    yes it is possible, with different extension name. Is the original file in .xlsx format then you want to save it in .xls format?

  9. #9
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    Quote Originally Posted by thisisgerald View Post
    @jessy142

    yes it is possible, with different extension name. Is the original file in .xlsx format then you want to save it in .xls format?
    Original file is .log extension, but i want it .xls

  10. #10
    Forum Contributor
    Join Date
    09-05-2012
    Location
    It's more fun in the Philippines :D
    MS-Off Ver
    Excel 2007
    Posts
    209

    Re: Macro - Save in same folder

    I think you're title is not accurate to what you want to happen or to your problem.

    You need a macro that reads text file then paste it to excel.

    You can attach a sample log file and the output you prefer.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  11. #11
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    An example;

    I have a file named: file1.log
    I open this with Excel, i make some changes in the sheet.
    Then i want a macro that saves it to the place where i opened file1.log and save it as file1.xls.
    But i want to use this macro with many different .log files, so all have different names.
    So the macro must read the opened file name, and save it with the same name, only with an other extension.


    - Jessy

  12. #12
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Macro - Save in same folder

    You could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  13. #13
    Registered User
    Join Date
    09-03-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: Macro - Save in same folder

    Quote Originally Posted by antoka05 View Post
    You could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

    When i use that code i get run-time error '1004':

    Method 'SaveAs' of object '_Workbook' failed

+ 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