Linking worksheets to a master worksheet and keeping values if the master worksheet is not present? Excel 2010

☆樱花仙子☆ 提交于 2019-12-13 13:26:43

问题


I have many worksheets and at present, every 3 months I have to go through these one by one to update information in just a few cells.

It would be great if I could create a master source file containing these few cells that get updated, that all my worksheets linked to, so that I could just update this file and all my files would then update.

The only trouble I have is that I then send these worksheets out to clients by email, each client gets a specific worksheet.

This would mean that the local links to the master source file would no longer be there and I'm assuming there would be errors. Is there some way that I could link my files, as desired, to a master file, be able to update the master file and have all the other files update accordingly, but then send only a single file to a client and keep the values from the master file.

I hope this is making sense! It's quite simple what I want to do, it's just a bit tricky putting it into words.

Any help or advice would be great!


回答1:


You would think there would be a simple way to do this out of the box, but it does present a problem. This not very elegant solution shows how to copy cells or ranges from a master workbook that you must have open when you are updating your client sheets. Obviously the client user won't have the master workbook and so the macro fails silently in that case. Put this code in your ThisWorkbook module of each client workbook.

Private Sub Workbook_Open()
    On Error Resume Next
    Dim master As Workbook
    Set master = Workbooks("master.xlsm")

    If master Is Nothing Then
    'the client is probably opening the wbook. do nothing
    Else 'copy your stuff here
        With Workbooks("master.xlsm")
            .Worksheets("Sheet1").Range("A1:D4").Copy _
                Destination:=Worksheets("Sheet1").Range("A1:D4")
        End With
    End If

End Sub



回答2:


I hope I understood your problem correctly. What we do is save the workbook as a different workbook with a different filename. We usually append "_sent.xlsx" to the workbook filename. Then open it, go to Data, Edit Links, and break all the links. Only the 'values' will remain in the work book. Save the workbook and you can send it out without having to worry about values that will break when they open it. And you still have your original file if you need to change anything.



来源:https://stackoverflow.com/questions/6047379/linking-worksheets-to-a-master-worksheet-and-keeping-values-if-the-master-worksh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!