خرید بک لینک

Vote count: 0

I want to copy a sheet from files X,Y and Z to a new file Master11Aug2016. If there already exists a file called Master11Aug2016 in the folder it works, but when there is not it returns an error on the copy line stating .

Dim place As String
place = "C:Users..."

Dim fname As String
dt = Format(CStr(Now), "ddmmmyy")
fname = "Master" & dt

Dim path As String
path = place & fname & ".xlsx"

Workbooks.Add
ActiveWorkbook.SaveAs Filename:=(path)

Dim X, Y, Z As String
X = Dir(place & "X.xlsx")
Y = Dir(place & "Y.xlsx")
Z = Dir(place & "Z.xlsx")

Workbooks.Open (X)
Workbooks(X).Sheets("Sheet1").Calculate
Workbooks(X).Sheets("Sheet1").Copy Before:=Workbooks(path).Sheets(1) [error here]
Workbooks(X).Close

...

So the code fails first time around. but then works the second time. Any help would be greatly appreciated. Cheers

asked 37 secs ago

برچسب: vba copy worksheet,vba copy worksheet to another workbook,vba copy worksheet to new workbook,vba copy worksheet and rename,vba copy worksheet to another worksheet,vba copy worksheet to end,vba copy worksheet with new name,vba copy worksheet name,vba copy worksheet to existing worksheet,vba copy worksheet subscript out of range, نویسنده: استخدام کار تاريخ: پنجشنبه 21 مرداد 1395 ساعت: 15:50

صفحه بندی