VBA Copy tables from excel to Wd
VBA Copy tables from excel to Wd
Salut,
Nu am experiente in VBA, dar am un cod prin care doresc sa copiez tabele din excel in word (fiecare tabel din cate un sheet este adus intr-un bookmark din Wd)(capul de tabel este in A1:F1), singura problema a codului este ca atunci cand tabelul nu contine informatii imi aduce tot tabelul gol in word, iar eu doresc in aceasta situatie sa-mi aduca doar capul de tabel.
Ma puteti ajuta cu modificarea codului a.i sa respecte cerintele? Multumesc
Nu am experiente in VBA, dar am un cod prin care doresc sa copiez tabele din excel in word (fiecare tabel din cate un sheet este adus intr-un bookmark din Wd)(capul de tabel este in A1:F1), singura problema a codului este ca atunci cand tabelul nu contine informatii imi aduce tot tabelul gol in word, iar eu doresc in aceasta situatie sa-mi aduca doar capul de tabel.
Ma puteti ajuta cu modificarea codului a.i sa respecte cerintele? Multumesc
-
- Mesaje: 435
- Membru din: Mar Dec 11, 2018 8:54 pm
Re: VBA Copy tables from excel to Wd
Poate am putea sa te ajutam daca pui si codul VBA, sa il putem eventual modifica.
藍
"I fear the day that technology will surpass our human interaction. The world will have a generation of idiots."
Albert Einstein
"I fear the day that technology will surpass our human interaction. The world will have a generation of idiots."
Albert Einstein
Re: VBA Copy tables from excel to Wd
Imi cer scuze, am crezut ca s.a atasat codul, cel putin daca nu ma insel i.am dat previzualizare si era atasat...cu scuzele de rigoare, am sa revin cu informatia, vineri, deoarece nu mai am acces la statia de lucru. Multumesc
Re: VBA Copy tables from excel to Wd
<t>Sub ExportExcelDataToWordDocument()<br/>
‘Dim wdExcelApp As Application ‘Excel is the default library (optional)<br/>
Dim wdWordApp As Word.Application ‘Word app<br/>
Application.ScreenUpdating = False<br/>
‘ Creating a new instance of Word<br/>
Set wdWordApp = New Word.Application ‘instantiate a new instance of Word 2010<br/>
With wdWordApp<br/>
‘ Making Word Visible on the screen<br/>
.Visible = True ‘iff false, document is invisible.<br/>
.Activate ‘ make it the top pane, bring it to the front.<br/>
””””””””””””””””””””””””””””””””””””””””””””””’<br/>
‘ create a new Word Document based on the specified template<br/>
””””””””””””””””””””””””””””””””””””””””””””””’<br/>
.Documents.Add “C:Usersstefan.georgescuDesktopTemplate fisa de esantionare – ver. 5-2019.dotm”<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“GestiuneSSC”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark1” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
‘****************<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“AlimATM”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark2” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
‘****************<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“DepRidAngajati”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark3” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
”””””””””””””””””””””””””””’<br/>
‘ Save WORD Document<br/>
”””””””””””””””””””””””””””’<br/>
Dim TheFileName As String<br/>
TheFileName = “C:Usersstefan.georgescuDesktopFisa.docx”<br/>
‘(SaveAs is for Office 2003 and earlier – deprecated)<br/>
.ActiveDocument.SaveAs2 TheFileName<br/>
‘replaces existing .doc iff exists<br/>
‘ Close Documents and Quit Word<br/>
.ActiveDocument.Close ‘close .DOCx<br/>
.Quit ‘exit Word<br/>
End With<br/>
Application.ScreenUpdating = True<br/>
‘MEMORY CLEANUP<br/>
Set wdWordApp = Nothing ‘garbage collection<br/>
‘Set wdExcelApp = Nothing ‘OPTIONAL<br/>
End Sub</t>
‘Dim wdExcelApp As Application ‘Excel is the default library (optional)<br/>
Dim wdWordApp As Word.Application ‘Word app<br/>
Application.ScreenUpdating = False<br/>
‘ Creating a new instance of Word<br/>
Set wdWordApp = New Word.Application ‘instantiate a new instance of Word 2010<br/>
With wdWordApp<br/>
‘ Making Word Visible on the screen<br/>
.Visible = True ‘iff false, document is invisible.<br/>
.Activate ‘ make it the top pane, bring it to the front.<br/>
””””””””””””””””””””””””””””””””””””””””””””””’<br/>
‘ create a new Word Document based on the specified template<br/>
””””””””””””””””””””””””””””””””””””””””””””””’<br/>
.Documents.Add “C:Usersstefan.georgescuDesktopTemplate fisa de esantionare – ver. 5-2019.dotm”<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“GestiuneSSC”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark1” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
‘****************<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“AlimATM”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark2” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
‘****************<br/>
‘as before, copy the whole table from sheet to clipboard.<br/>
Worksheets(“DepRidAngajati”).Activate<br/>
Range(“A1”, Range(“A1″).End(xlDown).End(xlToRight)).Copy<br/>
.Selection.GoTo what:=-1, Name:=”bookmark3” ‘ -1 means “wdgotobookmark”<br/>
.Selection.Paste ‘paste from the clipboard to the Word Doc.<br/>
”””””””””””””””””””””””””””’<br/>
‘ Save WORD Document<br/>
”””””””””””””””””””””””””””’<br/>
Dim TheFileName As String<br/>
TheFileName = “C:Usersstefan.georgescuDesktopFisa.docx”<br/>
‘(SaveAs is for Office 2003 and earlier – deprecated)<br/>
.ActiveDocument.SaveAs2 TheFileName<br/>
‘replaces existing .doc iff exists<br/>
‘ Close Documents and Quit Word<br/>
.ActiveDocument.Close ‘close .DOCx<br/>
.Quit ‘exit Word<br/>
End With<br/>
Application.ScreenUpdating = True<br/>
‘MEMORY CLEANUP<br/>
Set wdWordApp = Nothing ‘garbage collection<br/>
‘Set wdExcelApp = Nothing ‘OPTIONAL<br/>
End Sub</t>
-
- Mesaje: 435
- Membru din: Mar Dec 11, 2018 8:54 pm
Re: VBA Copy tables from excel to Wd
Te rog sa atasezi codul, curatat de acele ramasite de html si sa folosesti iconul </> pentru a-l posta aici.
1. sunt mai multe tabele intr-o foaie sau numai tabelul care trebuie copiat?
2. In Word acele bookmark-uri sunt in pagini diferite? sau cum?
3. Acele tabele sunt create (cu Insert Table) sau sunt denumiri generice "tabele"?
Am cateva intrebari:doresc sa copiez tabele din excel in word (fiecare tabel din cate un sheet este adus intr-un bookmark din Wd)(capul de tabel este in A1:F1),
1. sunt mai multe tabele intr-o foaie sau numai tabelul care trebuie copiat?
2. In Word acele bookmark-uri sunt in pagini diferite? sau cum?
3. Acele tabele sunt create (cu Insert Table) sau sunt denumiri generice "tabele"?
藍
"I fear the day that technology will surpass our human interaction. The world will have a generation of idiots."
Albert Einstein
"I fear the day that technology will surpass our human interaction. The world will have a generation of idiots."
Albert Einstein
Re: VBA Copy tables from excel to Wd
Salut, Indigo, intre timp am reusit sa fac macro.ul sa mearga. Multumesc mult