danboi1010
New Member
- Joined
- Nov 23, 2017
- Messages
- 13
Hi, I am trying to get a macro to insert the data held in cell a1 into a word letter.
This code does exactly what i want it to do but i cannot work out how to import the data held in a1 into the word letter.
I feel like it should be
but of course it's not!
Any help would be great. Thanks.Dan.
Code:
Private Sub CommandButton1_Click()
'Open Word
Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
Dim MyText As String
Dim Selection As String
Set WrdApp = CreateObject("Word.Application")
WrdApp.Visible = True
WrdApp.Activate
Set WrdDoc = WrdApp.Documents.Add
WrdApp.Selection.TypeText Text:="Hello"
WrdApp.Selection.TypeParagraph
WrdApp.Selection.TypeParagraph
WrdApp.Selection.TypeText Text:="Bye"
WrdApp.Selection.TypeParagraph
WrdApp.Selection.TypeParagraph
WrdApp.ActiveDocument.SaveAs Filename:="C:\Users\Dan.docx"
WrdApp.Quit
End Sub
This code does exactly what i want it to do but i cannot work out how to import the data held in a1 into the word letter.
I feel like it should be
Code:
WrdApp.Selection.cell = ("A1")
Any help would be great. Thanks.Dan.