Xin chào mọi người trên GPE,
Nhờ mọi người hướng dẫn mình về đường dẫn thư mục chứa tài liệu nguồn
Bình thường mình thấy nếu các file làm việc và file nguồn chung 1 folder thì nó là dạng ThisWorkbook.Path
Nếu file nguồn không nằm cùng thư mục thì như thế nào nhỉ?
Mình có search google : bằng cách đặt biến : spart = "link" --> chạy lệnh open file báo lỗi, báo lỗi ở dòng : Set Wb = Workbooks.Open(spart & "\" & WbName)
Nhờ mọi người giúp đỡ
Nhờ mọi người hướng dẫn mình về đường dẫn thư mục chứa tài liệu nguồn
Bình thường mình thấy nếu các file làm việc và file nguồn chung 1 folder thì nó là dạng ThisWorkbook.Path
Nếu file nguồn không nằm cùng thư mục thì như thế nào nhỉ?
Mình có search google : bằng cách đặt biến : spart = "link" --> chạy lệnh open file báo lỗi, báo lỗi ở dòng : Set Wb = Workbooks.Open(spart & "\" & WbName)
Nhờ mọi người giúp đỡ
Mã:
Sub CapNhat()
Dim Wb As Workbook, WbName As String, WsName As String, Darr(), LastR As Long, i As Long
Dim spart As String
spart = "\\192.168.14.1\HongLam\6. KHO"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
For j = 1 To 10
i = Cells(Rows.Count, j).End(xlUp).Row
If i > LastR Then LastR = i
Next j
Darr = Range("A2:J" & LastR).Value
WsName = ThisWorkbook.Name
WsName = Left(WsName, Len(WsName) - 5)
WbName = "Data_N.xlsx"
If Test(WbName) Then
Set Wb = Workbooks(WbName)
Else
'Set Wb = Workbooks.Open(ThisWorkbook.Path & "\" & WbName)
Set Wb = Workbooks.Open(spart & "\" & WbName)
End If
With Wb.Sheets(WsName)
.Range("A2:A9999").ClearContents
.Range("A2").Resize(UBound(Darr), 10) = Darr
End With
Wb.Close True
ActiveWorkbook.Save
MsgBox "Xong!"
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub