KVT Holland
New Member
- Joined
- May 10, 2017
- Messages
- 21
I've been trying to populate an excel template .dotx and saving it as .doc
I managed to get most parts of the code working. But its 4 in the morning and i cant figure out the last part;
Ive been failing to get the code i wanted to show working. But it should work as followed;
Groslijst is a dynamic range 6 columns and up to 3000 rows.
The Bookmark in Word is get "moved" by the page break.
There are 25 Bookmarks that need big ranges and 45 that need text from a single cell.
I started using only single cell named ranges thinking it shouldn't be hard to add the big tables.
I have no idea on how to add the ranges in to excel. I tried selecting the range and .copy .paste Paste special. Tables and ended up just trying everything i could find.
I home you guys can explain what i don't understand about exporting tables/ranges a to a bookmark.
Sincerely,
Koen.
I managed to get most parts of the code working. But its 4 in the morning and i cant figure out the last part;
Code:
[COLOR=#3366FF][FONT=Arial]Dim LastRow As Long
[/FONT][/COLOR][COLOR=#3366FF][FONT=Arial]LastRow = Groslijst.Range("A" & Rows.Count).End(xlUp).Row[/FONT][/COLOR]
Groslijst.Sheets("blad1").Range("A2:F" & Cells(Rows.Count, "a").End(xlUp).Row).Name = "Groslijst"
With New Word.Application
.Visible = True
.WindowState = wdWindowStateMaximize
With .Documents.Add(Template:="C:\Users\koenv\Desktop\Excel Biobeheer\RABP sjabloon clean coppy V2 6-11-2017.dotx")
With .Bookmarks
.Item("Groslijst").Range.InsertAfter Sheets("Data Sheet").Range("Groslijst").Text
End with
End with
End With
End sub
Ive been failing to get the code i wanted to show working. But it should work as followed;
Groslijst is a dynamic range 6 columns and up to 3000 rows.
The Bookmark in Word is get "moved" by the page break.
There are 25 Bookmarks that need big ranges and 45 that need text from a single cell.
I started using only single cell named ranges thinking it shouldn't be hard to add the big tables.
I have no idea on how to add the ranges in to excel. I tried selecting the range and .copy .paste Paste special. Tables and ended up just trying everything i could find.
Code:
[COLOR=#7D2727][FONT=inherit]Call CreateTableFromString(wdDoc.Bookmarks("tblplc_" & sTableName).Range, rInputData)
'[/FONT][/COLOR][FONT=Verdana]https://stackoverflow.com/questions/19916536/automated-word-template-creation-with-vba?noredirect=1&lq=1
[/FONT]
----------------------------------------------------------------------------------------
WordApp.Documents.Open WORDDOC
' Copies the named range "OrderRange" from the Excel book you are running this from.
ws.Range("OrderRange").Copy
' Pastes it to the bookmark "OrderBookmark" in your Word doc template.
WordApp.ActiveDocument.Bookmarks("OrderBookmark").Range.Paste
'https://www.mrexcel.com/forum/excel-questions/673873-macro-copy-paste-excel-range-into-word-doc-then-print-pdf.html
--------------------------------------------------------------
[COLOR=darkblue][FONT=Verdana]Sub[/FONT][/COLOR][FONT=Verdana] CertGenerator()[/FONT]
Sub CertGenerator()
Set Price = Sheets("Data Sheet").Range("Price")
With New Word.Application
.Visible = True
.WindowState = wdWindowStateMaximize
With .Documents.Add(Template:="C:\Administration\Documentation\Templates\Cert Template 2013.docx")
With .Bookmarks
.Item("Price").Range.InsertAfter Sheets("Data Sheet").Range("Price").Text
End With
.SaveAs ThisWorkbook.Path & "" & Sheets("Data Sheet").Range("Name").Text & " Cert " & Format(Date, "yyyy")
'.Close
End With
'.Quit
End With
End Sub
[COLOR=darkblue][FONT=Verdana]
[/FONT][/COLOR]'https://www.mrexcel.com/forum/excel-questions/706988-export-excel-ranges-word-bookmarks-using-vba-specific-formatting-place.html[COLOR=darkblue][FONT=Verdana]
[/FONT][/COLOR]'https://stackoverflow.com/questions/32739715/open-word-template-paste-excel-data-in-and-save
-----------------------------------------------------------------
.Item("testbm").Range.InsertAfter Worksheets("Sheet1").Range("A1").Value
'https://www.ozgrid.com/forum/forum/help-forums/excel-general/141223-update-word-document-from-excel-with-bookmarks-and-keep-bookmarks-with-vba
----------------------------------------------------------------
[URL]https://www.experts-exchange.com/articles/8933/How-to-quickly-and-accurately-populate-Word-documents-with-Excel-data-charts-and-images-including-Automated-Bookmark-generation.html[/URL]
-----------------------------------------------------------------
[URL]https://www.ozgrid.com/forum/forum/other-software-applications/excel-and-or-word-help/113582-excel-data-to-word-bookmarks[/URL]
---------------------------------------------------------------
[URL]https://msdn.microsoft.com/en-us/vba/excel-vba/articles/exporting-a-table-to-a-word-document[/URL]
I home you guys can explain what i don't understand about exporting tables/ranges a to a bookmark.
Sincerely,
Koen.
Last edited: