Office 2013과 Office 2016 모두에서 작동하도록 Microsoft Word 16.0 Object Library에 대한 참조를 제거하고 코드를 편집 할 가능성이 있습니까?

이 코드는 포함 된 Word 문서를 열고 데이터를 쓰고 사용자 데스크탑에 저장하기위한 것입니다. 그 후 Word 응용 프로그램을 종료합니다.

Sub opentemplateWord()
    Dim sh As Shape
    Dim objWord As Object, objNewDoc As Object ''Word.Document
    Dim objOL As OLEObject
    Dim wSystem As Worksheet
    Dim cell As Range
    Dim wdRng As Object 'Word.Range
    Dim xlRng As Excel.Range
    Dim tempFolderPath As String
    Dim filePath As String
    Dim fileTitle As String
    Set wSystem = ThisWorkbook.Sheets("Templates")
        ''The shape holding the object from 'Create from file'
        ''Object 2 is the name of the shape
    Set sh = wSystem.Shapes("LetterTemplate")
         ''The OLE Object contained
    Set objOL = sh.OLEFormat.Object
         'Instead of activating in-place, open in Word
    objOL.Verb xlOpen
    Set objWord = objOL.Object 'The Word document
    Dim objUndo As Object 'Word.UndoRecord
        'Be able to undo all editing performed by the macro in one step
    Set objUndo = objWord.Application.UndoRecord
    objUndo.StartCustomRecord "Edit In Word"
    With objWord
        'Cover page
    .Bookmarks("CoverPage").Range.Text = ThisWorkbook.Sheets("Other Data").Range("AK4").Value
    Set xlRng = ThisWorkbook.Sheets("Letter").Range("G3", ThisWorkbook.Sheets("Offer Letter").Range("G" & Rows.Count).End(xlUp))
    Set wdRng = .Range.Characters.Last
    For Each cell In xlRng
        wdRng.InsertAfter vbCr & cell.Offset(0, -5).Text
        Select Case LCase(cell.Value)
    Case "signature"
       Worksheets("Contact database").Shapes("Signature").Copy
        With wdRng
        .Paragraphs.Last.Range.Paste (wdPasteDefault)
        End With
    If ActiveDocument.TablesOfContents.Count = 1 Then _
        objWord.SaveAs2 Environ$("USERPROFILE") & "\Desktop\" & _
        ThisWorkbook.Sheets("Other Data").Range("AU2").Value & ".docx"
        Set objUndo = Nothing
        .Application.Quit False
    End With
    Set objWord = Nothing
End Sub

  • 답변 # 1

    Office 2013 시스템에서 참조를 설정하면 아무것도 변경하지 않고도 Office 2016 이상에서 작동합니다.

  • 이전 postgresql - Windows에서 pgpassconf가 제대로 작동하도록 수정하는 방법이 있습니까?
  • 다음 기존 nginx 구성에 prerenderio 사용