다음 Excel 컨텐츠를 워드 문서로 변환하려고합니다. 새 단어 보고서에는 학생 이름, 날짜, 제목, 원래 시험 시간 및 새 시험 시간이 포함됩니다.
Excel에서 단어 보고서를 생성하는 방법은 무엇입니까?
나는 이것을하기 위해 간단한 방법을 사용하려고 노력했다. 범위 (a79 : L85) & 범위 (A90 : L92)를 새 단어 문서에 복사합니다. 그러나 작동하지 않고 함께 두 테이블을 조인합니다 (동일한 행에).
Sub ExcelRangeToWord()
'PURPOSE: Copy/Paste An Excel Table Into a New Word Document
'NOTE: Must have Word Object Library Active in Order to Run _
(VBE > Tools > References > Microsoft Word 12.0 Object Library)
'SOURCE: www.TheSpreadsheetGuru.com
Dim tbl As Excel.RANGE
Dim tbl2 As Excel.RANGE
Dim WordApp As Word.Application
Dim myDoc As Word.Document
Dim WordTable As Word.Table
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
'Copy Range from Excel
Set tbl = ThisWorkbook.Worksheets(sheet9.Name).RANGE("A79:L85") 'copy the name ,subject and old exam time
Set tbl2 = ThisWorkbook.Worksheets(sheet99.Name).RANGE("A90:L92")'copy the new exam time
'Create an Instance of MS Word
On Error Resume Next
'Is MS Word already opened?
Set WordApp = GetObject(Class:="Word.Application")
'Clear the error between errors
Err.Clear
'If MS Word is not already open then open MS Word
If WordApp Is Nothing Then Set WordApp = CreateObject(Class:="Word.Application")
'Handle if the Word Application is not found
If Err.Number = 429 Then
MsgBox "Microsoft Word could not be found, aborting."
GoTo EndRoutine
End If
On Error GoTo 0
'Make MS Word Visible and Active
WordApp.Visible = True
WordApp.Activate
'Create a New Document
Set myDoc = WordApp.Documents.Add
'Copy Excel Table Range
tbl.Copy ' paste range1
tbl2.Copy 'paste range2
'Paste Table into MS Word
myDoc.Paragraphs(1).RANGE.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
'Autofit Table so it fits inside Word Document
Set WordTable = myDoc.Tables(1)
WordTable.AutoFitBehavior (wdAutoFitWindow)
EndRoutine:
'Optimize Code
Application.ScreenUpdating = True
Application.EnableEvents = True
'Clear The Clipboard
Application.CutCopyMode = False
End Sub
어떤 힌트 또는 방법은 다음과 같이 단어 보고서를 생성 할 수 있습니까?
출력이 필요하고 실습으로이 작업을 수행하지 않는 경우 편지 병합이 더 간단 해지고 훨씬 빠르게 실행됩니다. –
@ MihaiOvidiuDrăgoi 그러나 Excel을 사용하여 새 시간을 계산해야합니다. 개별 문서는 단어이어야합니다. 편지 병합이 수행 할 수 있습니까? 참조 링크가 있습니까? – Vito