Hi, patel45,
seems you´re having some kind of problem with this thread:
wb2name = "2st" & Right(wb2name, Len(wb1name) - 3)
wb2name hasn´t been assigned when being used, and I would have expected wb1name there.
@kramtelbuab:
there is no check if the files are open in Excel but this code would assume the active workbook to be 1st while the code still may be hosted in Personal.xlsb:
Sub EF925982()
'may be hosted in personal.xlsb,
'both other workbooks are open in Excel
'both workbooks only differ in first 3 characters in name
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim strwb2 As String
'set an object to the first workbook being the activeworkbook
Set wb1 = ActiveWorkbook.Name
'get the name and the object for the secon workbook
strwb2 = "2st" & Right(wb1.Name, Len(wb1.Name) - 3)
Set wb2 = Workbooks(strwb2)
'copy the worksheet
wb2.Sheets("Master").Copy After:=wb1.Worksheets(wb2.Worksheets.Count)
'clear objects
Set wb2 = Nothing
Set wb1 = Nothing
End Sub
I really do not like this approach very much and would rather work with GetOpenFilename for opening and setting objects for the workbooks.
Ciao,
Holger
Bookmarks