Excel: 별도 통합 문서의 셀에 대한 양방향 연결

Excel: 별도 통합 문서의 셀에 대한 양방향 연결

나는 아주 새로운 사람이고 이것을 올바르게 묻는 것인지 확실하지 않습니다. 정보를 편집하고 업데이트할 수 있도록 고객과 공유하고 싶은 Excel 스프레드시트가 있습니다. 그러나 나는 그의 계정이 아닌 여러 개의 다른 계정을 가지고 있기 때문에 한 섹션만 공유하고 싶거나 아마도 하나의 워크시트만 공유하고 싶습니다. 두 개의 개별 통합 문서를 업데이트하고 편집하고 싶지 않습니다. 내가 원하는 것은 내가 그 사람과 공유하는 통합 문서와 현재 통합 문서 사이에 양방향 링크를 만들어 하나가 변경되면 다른 하나도 자동으로 업데이트되고 그 반대의 경우도 마찬가지입니다.

이전 게시물이 워크시트 사이에서 이 작업을 수행하는 데 도움이 되었으며 정말 좋습니다(Christofer Weber에게 감사드립니다. 훌륭하게 작동합니다). VBA가 필요하다는 것을 알고 있지만 알아낼 수는 없습니다. 어떤 아이디어가 있나요? 워크시트에 사용되는 현재 VBA를 수정하고 싶었습니다.

현재 것

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range(Target.Address), Range("A2:D5")) Is Nothing Then
    Application.EnableEvents = False
    Sheets(1).Range(Target.Address).Value = Target
    Sheets(2).Range(Target.Address).Value = Target
    Sheets(3).Range(Target.Address).Value = Target
    Application.EnableEvents = True
End If
End Sub

지금까지 제가 가지고 있는 내용은 이렇지만 윗줄은 정확하지 않은 것으로 알고 있습니다.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range(Target.Address), Range("A2:D5")) Is Nothing Then
    Application.EnableEvents = False
    Workbooks("Test excel workbook 1 - macro.xlsm").Sheets(1).Range(Target.Address).Value = Target
    Workbooks("Test excel workbook 2 - macro.xlsm").Sheets(1).Range(Target.Address).Value = Target
    Application.EnableEvents = True
End If
End Sub

답변1

나는 이것을 테스트해 보았는데, 이 정도면 당신에게 도움이 될 것이라고 생각합니다. 하지만 제가 주목한 몇 가지 사항이 있습니다.

가장 먼저 주목해야 할 점은 Intersect여러 워크시트의 범위를 비교하는 경우에는 이 방법이 작동하지 않는다는 것입니다.이 질문. 여기서는 명시적으로 그렇게 하지 않았지만 VBA가 암시적으로 결정하도록 허용하는 대신 작업할 워크시트를 지정하는 것이 현명하다고 생각합니다.

두 번째는 예를 들어 다음 줄입니다.

Workbooks("Test excel workbook 1 - macro.xlsm").Sheets(1).Range(Target.Address).Value = Target

개인적으로 한 범위의 값을 다음 범위로 설정하는 대신 다른 범위로 설정하는 것이 이상하다고 생각합니다.대신 다음과 같이 표시됩니다.

Workbooks("Test excel workbook 1 - macro.xlsm").Sheets(1).Range(Target.Address).Value = Target.Value

내가 생각해낸 코드는 다음과 같습니다.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Const filePath As String = "C:\some\file\path\otherthing.xlsm"
    Dim otherwb As Workbook
    Dim otherws As Worksheet
    Dim thisws As Worksheet
    Dim rangeIntersection As Range

    'this will allow opening the other workbook without
    'displaying the white UI
    Application.ScreenUpdating = False

    'setting a reference to this worksheet
    Set thisws = ThisWorkbook.Worksheets("Sheet1")
    'opens an unopened workbook or it will simply set a reference
    'to this workbook if it's already opened
    Set otherwb = Excel.Workbooks.Open(filePath)
    'just chose a random worksheet
    Set otherws = otherwb.Worksheets(1)
    'doing the intersection
    Set rangeIntersection = _
        Application.Intersect(Range(Target.Address), _
        thisws.Range("A2:D5"))

    If Not rangeIntersection Is Nothing Then
        Application.EnableEvents = False
        otherws.Range(Target.Address).Value = Target.Value
        Application.EnableEvents = True
    End If

    'uncomment this if you do want to close the wb at the end
'    otherwb.Save
'    otherwb.Close
    Application.ScreenUpdating = True
End Sub

도움이 되길 바랍니다

관련 정보