mark hansen
Well-known Member
- Joined
- Mar 6, 2006
- Messages
- 534
- Office Version
- 2016
- Platform
- Windows
I have some code I've used in a few projects that creates a new word document (from excel vba) and pastes in a string. I remove the last character (a ") and set the font and font size. What new in this part of the code is I want to set the style to No Space. I recorded the vba from word and paste3d in the lines, but I get an error on the Style line... Any ideas on what I'm doing wrong.
Thanks for any ideas
Mark
Code:
Sub CreateWordDoc()
Dim wdapp As Word.Application
Set wdapp = New Word.Application 'Start word
With wdapp
.Visible = True 'See Word on Task bar
.Activate 'Bring word to the front
.Documents.Add
End With
'===========Copy text from cell====================================
Range("o12").Copy
'===================================================================
With wdapp
.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
.Selection.TypeBackspace
.Selection.HomeKey Unit:=wdStory
.Selection.Delete Unit:=wdCharacter, Count:=1
.Selection.WholeStory
.Selection.Style = ActiveDocument.Styles("No Spacing")
.Selection.Font.Name = "Arial"
.Selection.Font.Size = 12
.Selection.Collapse
End With
End Sub
Thanks for any ideas
Mark