11-18-2020 07:10 AM
11-18-2020 07:10 AM
I am trying to create a word document from an Excel sheet.
For instance, in my excel table, I have different columns. One of them has the title of "colour". I can FILTER this column by the name of the different colours (eg "blue" , "green", "yellow" etc.).
Let's say I filter my column with the colour "blue".
What I would like to do in a VBA script, is to select all these rows that have the colour "blue" in commun and copy-paste them in a word document.
I thought I had it, but with the script I am using, I do not know why, but only the titles of my different columns is pasted, regardless what I define.
If anyone has already done such a thing, or knows how to fix this script, I would be grateful for your help!
Sub TestOne() Dim appWD As Word.Application, wbXL As Excel.Workbook Set appWD = CreateObject("Word.Application.16") appWD.Visible = True debut = Range("A13").End(xlUp).Row fin = Range("A15").End(xlUp).Row For i = debut To fin 'Copy the current row Worksheets("Sheet1").Rows(i).Copy 'tell word to create new document. appWD.Documents.Add 'Tell Word to paste the contents of the clipboard into the new document. appWD.Selection.Paste Next i 'Close the new Word document. appWD.ActiveDocument.Close 'Save the new document with a sequential file name. appWD.ActiveDocument.SaveAs Filename:="File" ' Close the new Word application. appWD.Quit Set appWD = Nothing End Sub
11-18-2020 10:22 AM
When I try to combine your description with your code,
I get totally confused and can't understand your plan.
Maybe it's me, maybe it's in the translation or maybe it's Johnny’s fault... Johnny Walker the blue bottle :).
Therefore, I would recommend you send a file (without sensitive data) where you can explain your plan on the basis of the file. So everyone is helped, the helpers and the helping ones.
*Knowledge of Excel version and the operating system is a must have if you want to proposing a reasonable solution (Example: office version e.g. 2016 or 2019 or 365 web or 365 pro, etc) and your operating system (e.g. Win10 (2004), Win 10 (1903), Mac, etc.).
Thank you for your understanding and patience
I know I don't know anything (Socrates)