0

I have a macro file, which on opening will create a file and save it in a folder.

I have created another macro to open the above macro file.

My question here is to move the file created by the above macro to a different folder.

Please help.

Below is my code:

    Sub fcr_macro()

    Dim wb As Workbook
    Dim clname, compname As String
    clname = Range("D2").Value
    compname = Range("D3").Value
    Set wb = Workbooks.Open(filename)

    wb.Close
    End Sub

Just to give a little more description:

the codeline:

    Set wb = Workbooks.Open(filename) 

will open a file that contains a macro. And this macro will create a file in a folder.

I want this file created by above macro to be moved to a destination folder. And I want this to be accomplished in the above code.

Please Note: The macro that runs upon file open cant be changed due to some issues.

Could you please throw some light on this

Thanks

  • [`FileCopy "C:\source\...", "D:\destination"`](https://www.rondebruin.nl/win/s3/win026.htm) – Marcucciboy2 Jun 27 '18 at 16:48
  • Nope... this will not help... As the file is created at run time and the filename of the new file can be different each time the macro is run. – user3228901 Jun 27 '18 at 16:50
  • you would just change the `"D:\destination..."` to `filename` to copy the file. Then you would say `Kill "C:\source\..."` to effectively "move" it. However, if you click on my first comment it is a link to a site with several functions you can use - one of which is named `Move_Certain_Files_To_New_Folder()` – Marcucciboy2 Jun 27 '18 at 16:58
  • 2
    Doesn't your code know what the file name is? – Mathieu Guindon Jun 27 '18 at 17:03
  • If you know the folder the macro will dump the file into, you could determine its name by finding the most recently created file in that folder. See [this question](https://stackoverflow.com/questions/25490868/finding-latest-file-in-a-folder-and-opening-it-vba-access) for an example of determining the most recently created file in VBA. It's a less than ideal solution but if you can't change the legacy macro it should be a reasonable workaround. – LittleBoxOfSunshine Jun 27 '18 at 17:04
  • Hi Chris, I tried the second code in the link you provided and its is giving error "Overflow". I replaced '~' with a valid name. – user3228901 Jun 27 '18 at 19:56

0 Answers0