Hi all,
some background to my question:
I have several xlsx files in a folder and this code below is part of a larger macro to assemble data from these sheets into a management overview.
This code has run several times, without a glitch, but I was asked to make sure that the source files were saved with the same sheet activated. I added the marked line, but then the code no longer closed the active workbook before continuing, running into a 'you already have xxxx.xlsx opened. Do you want to open xxxx.xlsx again anyway' message.
Anyone an idea why the bolded line is interfering with the second line below?
As you might get from the code: I need to save the source files again, as some updating is done in the process as well. So the overview file feeds info to the source files.
some background to my question:
I have several xlsx files in a folder and this code below is part of a larger macro to assemble data from these sheets into a management overview.
This code has run several times, without a glitch, but I was asked to make sure that the source files were saved with the same sheet activated. I added the marked line, but then the code no longer closed the active workbook before continuing, running into a 'you already have xxxx.xlsx opened. Do you want to open xxxx.xlsx again anyway' message.
Anyone an idea why the bolded line is interfering with the second line below?
As you might get from the code: I need to save the source files again, as some updating is done in the process as well. So the overview file feeds info to the source files.
Code:
MyFile = Dir(MyPath & "*.xlsx")
Do While Len(MyFile) > 0
Set wkbSource = Workbooks.Open(MyPath & MyFile)
Set wksSource = wkbSource.Worksheets("Sales Prognose")
Set wksAdjust = wkbSource.Worksheets("VF")
'change the source sheet name accordingly
Dim copy As Range
Set copy = Worksheets("Sales Prognose").Range("B8:B20")
Dim copy2 As Range
Set copy2 = Worksheets("Sales Prognose").Range("D8:O20")
Dim copy3 As Range
Set copy3 = Worksheets("Sales Prognose").Range("B2")
ThisWorkbook.Activate
Range("paste").Value = copy.Value
Range("paste_2") = copy2.Value
Range("paste_3") = copy3.Value
wksAdjust.Range("C4:N16").Formula = "=SUMIFS(overview.xlsm!TSTSUD[to],overview.xlsm!TSTSUD[rep],'Sales Progn'!R2C2,overview.xlsm!TSTSUD[mnd],VF!R3C,overview.xlsm!TSTSUD[Prod],VF!RC1)"
wksAdjust.Range("C4:N16").copy
wksAdjust.Range("C4:N16").PasteSpecial xlPasteValues
[B] Worksheets("Sales Prognose").Activate[/B]
Application.CutCopyMode = False
wkbSource.Close savechanges:=True
'wkbSource.Close
MyFile = Dir
Last edited: