View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] u208839@hotmail.com is offline
external usenet poster
 
Posts: 8
Default Run macro from active workbook whose name keeps changing

Hello,

I have a macro that copies data from the active sheet to a separate sheet. Although the MBC Data Backup.xlsb file will never change, the name of the active workbook where the macro resides "Iron Horse MBC Listing 0.3.0.xlsb" will change from time to time and causes this scrip to fail. How can I make this work without referencing the actual name of the active file?


Sub Backup()

' Backup Macro

Workbooks.Open Filename:="C:\NSD\Personal\MBC Data Backup.xlsb"
Range("A9:N20000").Select
Selection.ClearContents
Range("A9").Select

Windows("Iron Horse MBC Listing 0.3.0.xlsb").Activate
Sheets("Data").Select
Range("A9:N20000").Select
Selection.Copy

Windows("MBC Data Backup.xlsb").Activate
Range("A9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("A9").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWindow.Close
Range("A9").Select

Sheets("Cover").Select

End Sub