Link từ excel sang word

Liên hệ QC
Tôi tuân thủ nội quy khi đăng bài

truong124

Thành viên mới
Tham gia
19/11/16
Bài viết
40
Được thích
2
Chào mọi người, hiện em mới nhận việc mới, gặp vấn đề về word và excel. Em có nhiều file word với nội dung khác nhau, nhưng có một vài câu lặp đi lặp lại giữa các file word, em muốn link các nội dung đó từ 1 file excel sang word, khi thay đổi file excel thì cập nhật trên các file word. Em dùng copy paste link & keep source fomatting nhưng lại bị lỗi xuống dòng.
 
Bạn có thể sử dụng tính năng "Mail Merge" trong Word để liên kết dữ liệu từ Excel vào Word. Bạn cần tạo một bảng tính trong Excel chứa các nội dung cần liên kết, sau đó trong Word, chọn "Mail Merge" và chọn nguồn dữ liệu là Excel. Bạn có thể sử dụng các trường trong Excel để liên kết với các vị trí trong Word. Khi dữ liệu trong Excel thay đổi, các nội dung tương ứng trong Word cũng sẽ được cập nhật tương tự.
1675753206561.png
 
xin phép bạn truong124, mình cũng đang làm file giống như cách của bạn truong124
, hiện tại mình đã cập nhật được bên word khi thay đổi bên excel, giờ mình muốn thay đổi đường dẫn của toàn bộ link trong file word thì phải làm như thế nào? mong mọi người giúp đỡ.
nếu thay đổi từng cái 1 thì rất mất thời gian.
 
xin phép bạn truong124, mình cũng đang làm file giống như cách của bạn truong124
, hiện tại mình đã cập nhật được bên word khi thay đổi bên excel, giờ mình muốn thay đổi đường dẫn của toàn bộ link trong file word thì phải làm như thế nào? mong mọi người giúp đỡ.
nếu thay đổi từng cái 1 thì rất mất thời gian.
Bạn vào mục Info của Word và đổi link nhé!
wVvMG2uIUWCcYxb-imV3wqt81b_cCFgE9MsJ1P-61tepAZAWrMsTJmMI1a2K0L-B_1hkCDhKKoDuSkreRZdqwsKbE5wxQc-lVDSzcnfsYLc

https://jumpshare.com/embed/XzVDkUNscpyMnkwkr2XW
 
Lần chỉnh sửa cuối:
Ngoài ra bạn @truong124 có thể tham khảo cách trộn file của bác @ongke0711 ở đây nhé!
Cách bạn chỉ mình đã làm rồi và cần nhập đi nhập lại nhiều lần cho từng link nên không khả thi. Hay do mình làm không đúng cách. Bạn có thể chỉ giúp mình chi tiết hơn được không?
cảm ơn bạn hoangtuan, rất mong nhận được sự giúp đỡ từ bạn.
 
Cách bạn chỉ mình đã làm rồi và cần nhập đi nhập lại nhiều lần cho từng link nên không khả thi. Hay do mình làm không đúng cách. Bạn có thể chỉ giúp mình chi tiết hơn được không?
cảm ơn bạn hoangtuan, rất mong nhận được sự giúp đỡ từ bạn.
Thử dùng code này xem sao.
Mã:
Sub Update_Link()
Dim fieldCount As Integer, x As Long
Dim dlgSelectFile As FileDialog
Dim selectedFile As Variant
Dim W As Document
Application.DisplayAlerts = wdAlertsNone
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
    .Filters.Add "Word file", "*.doc?", 1
    If .Show = -1 Then
        For Each selectedFile In .SelectedItems
            Set W = Documents.Open(selectedFile, False)
            With W
              fieldCount = .Fields.Count
              For x = 1 To fieldCount
                With .Fields(x)
                  If .Type = 56 Then
                    'only update Excel links. Type 56 is an excel link
                    .LinkFormat.SourceFullName = "C:\Users\Administrator\Downloads\Data1.xlsx"
                    .Update
                    .LinkFormat.AutoUpdate = True
                    DoEvents
                  End If
                End With
              Next x
              W.Close True
            End With
        Next selectedFile
    End If
End With
Set dlgSelectFile = Nothing
Application.DisplayAlerts = wdAlertsAll
End Sub
 
Thử dùng code này xem sao.
Mã:
Sub Update_Link()
Dim fieldCount As Integer, x As Long
Dim dlgSelectFile As FileDialog
Dim selectedFile As Variant
Dim W As Document
Application.DisplayAlerts = wdAlertsNone
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
    .Filters.Add "Word file", "*.doc?", 1
    If .Show = -1 Then
        For Each selectedFile In .SelectedItems
            Set W = Documents.Open(selectedFile, False)
            With W
              fieldCount = .Fields.Count
              For x = 1 To fieldCount
                With .Fields(x)
                  If .Type = 56 Then
                    'only update Excel links. Type 56 is an excel link
                    .LinkFormat.SourceFullName = "C:\Users\Administrator\Downloads\Data1.xlsx"
                    .Update
                    .LinkFormat.AutoUpdate = True
                    DoEvents
                  End If
                End With
              Next x
              W.Close True
            End With
        Next selectedFile
    End If
End With
Set dlgSelectFile = Nothing
Application.DisplayAlerts = wdAlertsAll
End Sub
Thử dùng code này xem sao.
Mã:
Sub Update_Link()
Dim fieldCount As Integer, x As Long
Dim dlgSelectFile As FileDialog
Dim selectedFile As Variant
Dim W As Document
Application.DisplayAlerts = wdAlertsNone
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
    .Filters.Add "Word file", "*.doc?", 1
    If .Show = -1 Then
        For Each selectedFile In .SelectedItems
            Set W = Documents.Open(selectedFile, False)
            With W
              fieldCount = .Fields.Count
              For x = 1 To fieldCount
                With .Fields(x)
                  If .Type = 56 Then
                    'only update Excel links. Type 56 is an excel link
                    .LinkFormat.SourceFullName = "C:\Users\Administrator\Downloads\Data1.xlsx"
                    .Update
                    .LinkFormat.AutoUpdate = True
                    DoEvents
                  End If
                End With
              Next x
              W.Close True
            End With
        Next selectedFile
    End If
End With
Set dlgSelectFile = Nothing
Application.DisplayAlerts = wdAlertsAll
End Sub

Thử dùng code này xem sao.
Mã:
Sub Update_Link()
Dim fieldCount As Integer, x As Long
Dim dlgSelectFile As FileDialog
Dim selectedFile As Variant
Dim W As Document
Application.DisplayAlerts = wdAlertsNone
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
    .Filters.Add "Word file", "*.doc?", 1
    If .Show = -1 Then
        For Each selectedFile In .SelectedItems
            Set W = Documents.Open(selectedFile, False)
            With W
              fieldCount = .Fields.Count
              For x = 1 To fieldCount
                With .Fields(x)
                  If .Type = 56 Then
                    'only update Excel links. Type 56 is an excel link
                    .LinkFormat.SourceFullName = "C:\Users\Administrator\Downloads\Data1.xlsx"
                    .Update
                    .LinkFormat.AutoUpdate = True
                    DoEvents
                  End If
                End With
              Next x
              W.Close True
            End With
        Next selectedFile
    End If
End With
Set dlgSelectFile = Nothing
Application.DisplayAlerts = wdAlertsAll
End Sub
cảm ơn anh, a có thể hướng dẫn e sử dụng code này được không ạ?
 
Thử dùng code này xem sao.
Mã:
Sub Update_Link()
Dim fieldCount As Integer, x As Long
Dim dlgSelectFile As FileDialog
Dim selectedFile As Variant
Dim W As Document
Application.DisplayAlerts = wdAlertsNone
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
    .Filters.Add "Word file", "*.doc?", 1
    If .Show = -1 Then
        For Each selectedFile In .SelectedItems
            Set W = Documents.Open(selectedFile, False)
            With W
              fieldCount = .Fields.Count
              For x = 1 To fieldCount
                With .Fields(x)
                  If .Type = 56 Then
                    'only update Excel links. Type 56 is an excel link
                    .LinkFormat.SourceFullName = "C:\Users\Administrator\Downloads\Data1.xlsx"
                    .Update
                    .LinkFormat.AutoUpdate = True
                    DoEvents
                  End If
                End With
              Next x
              W.Close True
            End With
        Next selectedFile
    End If
End With
Set dlgSelectFile = Nothing
Application.DisplayAlerts = wdAlertsAll
End Sub
anh xem giúp e vs ạ. Cảm ơn anh.
 

File đính kèm

  • アンカーボルト強度計算ver1.docx
    154.7 KB · Đọc: 1
  • アンカーボルト強度重量計算表.xlsx
    43.2 KB · Đọc: 2
cảm ơn anh, a có thể hướng dẫn e sử dụng code này được không ạ?
Đoạn mã này là một macro để cập nhật các liên kết giữa các tài liệu Word và các tệp Excel. Nó sử dụng đối tượng FileDialog để chọn một hoặc nhiều tệp Word, sau đó lặp qua các trường trong mỗi tài liệu và thay đổi nguồn của bất kỳ liên kết Excel nào thành một đường dẫn tệp được chỉ định. Nó cũng đặt định dạng liên kết để tự động cập nhật và đóng tài liệu sau khi lưu các thay đổi.

Macro này có thể hữu ích nếu bạn muốn thay đổi nguồn dữ liệu của nhiều tài liệu Word có các bảng hoặc biểu đồ Excel được liên kết. Tuy nhiên, bạn có thể muốn sửa đổi mã để phù hợp với nhu cầu của bạn, chẳng hạn như sử dụng một biến cho đường dẫn tệp mới, hoặc kiểm tra loại liên kết trước khi cập nhật nó.

Để sử dụng bạn làm như hình sau:
giphy.gif

Bài đã được tự động gộp:

anh xem giúp e vs ạ. Cảm ơn anh.
Mình không rõ Vba có nhận rõ tên file bằng tiếng Trung/Nhật không nên bạn cứ chuyển tên file excel thành chữ cái abc, sau đó thay đường dẫn của file excel vào đường dẫn trong vba là được nhé!
SCs1x.gif
 
Lần chỉnh sửa cuối:
Đoạn mã này là một macro để cập nhật các liên kết giữa các tài liệu Word và các tệp Excel. Nó sử dụng đối tượng FileDialog để chọn một hoặc nhiều tệp Word, sau đó lặp qua các trường trong mỗi tài liệu và thay đổi nguồn của bất kỳ liên kết Excel nào thành một đường dẫn tệp được chỉ định. Nó cũng đặt định dạng liên kết để tự động cập nhật và đóng tài liệu sau khi lưu các thay đổi.

Macro này có thể hữu ích nếu bạn muốn thay đổi nguồn dữ liệu của nhiều tài liệu Word có các bảng hoặc biểu đồ Excel được liên kết. Tuy nhiên, bạn có thể muốn sửa đổi mã để phù hợp với nhu cầu của bạn, chẳng hạn như sử dụng một biến cho đường dẫn tệp mới, hoặc kiểm tra loại liên kết trước khi cập nhật nó.

Để sử dụng bạn làm như hình sau:
giphy.gif

Bài đã được tự động gộp:


Mình không rõ Vba có nhận rõ tên file bằng tiếng Trung/Nhật không nên bạn cứ chuyển tên file excel thành chữ cái abc, sau đó thay đường dẫn của file excel vào đường dẫn trong vba là được nhé!
SCs1x.gif
dạ để e làm thử, e cảm ơn anh hoangtuan.net
 
Web KT
Back
Top Bottom