one4youman
New Member
- Joined
- Oct 5, 2018
- Messages
- 13
I am looking to create an Excel macro that when ran will open a new word document, add a few lines of Text, copy a table / range from Excel, paste the range to fit, and then to run through a loop copying cells from Excel and pasting the text into word from a specified range, but only if the cell is not blank.
For example:
Copy excel range SBF!B2:H20
Open a new word document, insert and insert text:
Add todays date centered
Paste the Excel Range that was copied (Paste as a table and fit to width)
I would then like for the macro to loop through a range (SBF!B8:B17) within Excel (10 cells within a column), copy the cell text, and then paste the cell text into the word document without formatting, and adding text under each item, before continuing with the loop.
For Example:
Skip B10 as it’s blank.
Copy cell B11 and paste into Word. (Keep text only then make the text bold)
And continue the loop through the remaining cells ending with B17.
”
Thank you in advance,
John
For example:
Copy excel range SBF!B2:H20
Open a new word document, insert and insert text:
Code:
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:="STATUS BY FEATURE REPORT"
Selection.TypeParagraph ‘Inserts a return / enter key
Add todays date centered
Code:
Selection.TypeParagraph
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeText Text:="Status:"
Selection.TypeParagraph
Selection.TypeParagraph
Paste the Excel Range that was copied (Paste as a table and fit to width)
Code:
Selection.PasteExcelTable False, False, False
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Description of Order:"
Selection.TypeParagraph
Selection.TypeText Text:="Add Description of items ordered:"
Selection.TypeParagraph
Selection.TypeText Text:="ADJUSTMENT:”
Selection.TypeParagraph
I would then like for the macro to loop through a range (SBF!B8:B17) within Excel (10 cells within a column), copy the cell text, and then paste the cell text into the word document without formatting, and adding text under each item, before continuing with the loop.
For Example:
Code:
Copy cell B8 and paste into Word. (Keep text only then make the text bold)
Selection.TypeText Text:="Add Description of feature.”
Selection.TypeParagraph
Copy cell B9 and paste into Word. (Keep text only then make the text bold)
Selection.TypeText Text:="Add Description of feature.”
Selection.TypeParagraph
Skip B10 as it’s blank.
Copy cell B11 and paste into Word. (Keep text only then make the text bold)
Code:
Selection.TypeText Text:="Add Description of feature.”
Selection.TypeParagraph
And continue the loop through the remaining cells ending with B17.
Code:
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Action Plan” (Make this text bold)
Selection.TypeParagraph
Selection.TypeText Text:="Add Closing Report.
Thank you in advance,
John
Last edited by a moderator: