I’m new with VBA, I took little by little pieces from different codes and I have a code which supposed to check first if the file exists, if it does, then it makes new sheet on existing workbook with name “WK 40” and copies all information from that file, mostly important – with links, so in case if in original file will be added something, then it will update automatically in my file. I have an error “Named argument not found” showing me on “Link:=True”.
Sub CheckFileExists()
Dim strFileName As String
Dim strFileExists As String
Dim sourceWorkbook As Workbook
Dim targetWorkbook As Workbook
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
strFileName = "H:AmberSharedProductionNEW PURCHASE2023-2024Purchase Wk 40 29.04.24-05.05.24.xlsx"
strFileExists = Dir(strFileName)
If strFileExists <> "" Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "WK 40"
Set sourceWorkbook = Workbooks.Open("H:AmberSharedProductionNEW PURCHASE2023-2024Purchase Wk 40 29.04.24-05.05.24.xlsx")
Set sourceSheet = sourceWorkbook.Sheets("WK 40")
Set targetSheet = ThisWorkbook.Sheets("WK 40")
sourceSheet.Range("A1:AB850").Copy
targetSheet.Range("A1").PasteSpecial Paste:=xlPasteAll, Link:=True
sourceWorkbook.Close SaveChanges:=False
Else
MsgBox "The selected file doesn't exist"
End If
End Sub
I tried to change that line with targetSheet.Paste Link:=True
, all information is copied with links to original files, but all text is not saving it’s type So the date and time are shown incorrectly
I tried to remove that “Link:=True” and everything is copying correctly, but without links of course