bug of word vba RRS feed

  • 질문

  • Hello Everyone,

    this code copies data from original document's original tables

    and pastes to documents that running vba codes.

    and I didn't put any code to make changes to original tables and documents, 

    but original table's contents is changed after vba code runs. why this happens?

    thank you for your reply in advance

    and sorry for my bad english...

    Sub ExperimentForBug()
        Dim MyTable As Table
        Set MyTable = ThisDocument.Tables(6)
        Dim DocumentObject As Document
        Set DocumentObject = Documents.Open(ThisDocument.Path & "\Target.doc")
        Dim OriginalTable As Table
        Set OriginalTable = DocumentObject.Tables(1)
        Dim CounterForRepetitiveStatement As Integer
        For CounterForRepetitiveStatement = 2 To MyTable.Range.Rows.Count
            MyTable.Cell(CounterForRepetitiveStatement, 1).Range.Text = ""
        OriginalTable.Cell(6, 2).Range.Copy
        MyTable.Cell(2, 1).Range.Paste
        OriginalTable.Cell(9, 2).Range.Copy
        MyTable.Cell(3, 2).Range.Paste
        Dim MissRow As Long
        Dim RecurrenceRow As Long
        For CounterForRepetitiveStatement = 2 To MyTable.Rows.Count
            If InStr(1, MyTable.Cell(CounterForRepetitiveStatement, 2).Range.Text, "Miss", vbTextCompare) <> 0 Then
                MissRow = CounterForRepetitiveStatement
            ElseIf InStr(1, MyTable.Cell(CounterForRepetitiveStatement, 2).Range.Text, "Recurrence", vbTextCompare) <> 0 Then
                RecurrenceRow = CounterForRepetitiveStatement
            End If
        OriginalTable.Cell(10, 2).Range.Copy
        MyTable.Cell(MissRow + 1, 2).Range.Paste
        OriginalTable.Cell(11, 2).Range.Copy
        MyTable.Cell(RecurrenceRow, 2).Range.Paste
        For CounterForRepetitiveStatement = 3 To MyTable.Rows.Count
            If CounterForRepetitiveStatement <> MissRow And CounterForRepetitiveStatement <> RecurrenceRow Then
                MyTable.Cell(CounterForRepetitiveStatement, 2).Range.Text = ""
            End If
        Set DocumentObject = Nothing
    End Sub

    2018년 6월 10일 일요일 오후 12:31