엑셀 범위를 새 워드 문서로 복사하고 싶습니다. 일부는 수동으로 숨기려고합니다. , 나는 내 VB 프로그램을 실행하고 자동으로 새로운 단어 문서에 붙여 넣습니다.엑셀 테이블 범위를 추출하고 새 워드 문서로 복사
그러나 범위와 복사하여 그림 파일의 새 단어 문서 에 붙여 넣습니다. 에 단어 표 형식을 붙여 넣으려고합니다. 그러나 단어 표 형식은 가로 방향 A4 단어 형식에 가장 잘 맞아야합니다. 어떻게해야합니까? 여기
내 코드입니다 :'Tbl.CopyPicture Appearance:=xlScreen, Format:=xlPicture 'this line ...
Tbl.Copy '...replace with this line
다음,이 같은 .PasteExcelTable method
을 트리거 할 수 있습니다 : 모든
Sub gen()
Dim tbl0 As Excel.RANGE
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
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("17-18") ' Change e.g. sheet9.Name
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
'Value1 = Me.TextBox1.Value
'Value2 = Me.TextBox2.Value
'ws.Rows("84:89").EntireRow.Hidden = True 'ADJUST AS APPROPRIATE
'Copy Range from Excel
'Set tbl0 = ws.RANGE("A78:I83")
'Set Tbl = ws.RANGE(Value1, Value2)
Set Tbl = ws.RANGE(Selection.Address(ReferenceStyle:=xlA1, _
RowAbsolute:=False, ColumnAbsolute:=False))
' Set tbl2 = ws.Range("A90:I92")
'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
'Trigger copy separately for each table + paste for each table
Tbl.CopyPicture Appearance:=xlScreen, Format:=xlPicture
wordApp.Selection.Paste
wordApp.Selection.TypeParagraph
wordApp.Selection.PageSetup.Orientation = wdOrientLandscape
' resize_all_images_to_page_width myDoc
EndRoutine:
'Optimize Code
Application.ScreenUpdating = True
Application.EnableEvents = True
'Clear The Clipboard
Application.CutCopyMode = False
ws.Rows.EntireRow.Hidden = False
End Sub
기록 적합한 붙여 넣기 방법을 수행 Word에서 매크로. 녹음 된 코드를보십시오. –
가능한 해결책 :'Excel' 매크로를 통해'Word' 테이블을 만들고,'Tbl' 값을 배열에 넣고, 생성 된'Word' 테이블에 할당하십시오. – AntiDrondert