Hi!
In the code below, my values are getting exported to a document I created in Word. Now I would really much like them to be a specific place, so that I can get them in the middle of a sentence. I tried all kinds of bookmark-codes, but nothing seems to be working. The specific value just gets in the top of the document instead of in the text.
Can anyone help me?
Code:
Dim WordApp As Object
Set WordApp = CreateObject("word.Application")
WordApp.Visible = True
WordApp.Documents.Open "S:\BOKIS skabeloner\MB.docx"
Dim i As Integer
Dim strValue As String
For i = 5 To 5
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 2)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 3)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 4)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 6)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
Next i
End Sub
Regards, MB
In the code below, my values are getting exported to a document I created in Word. Now I would really much like them to be a specific place, so that I can get them in the middle of a sentence. I tried all kinds of bookmark-codes, but nothing seems to be working. The specific value just gets in the top of the document instead of in the text.
Can anyone help me?
Code:
Dim WordApp As Object
Set WordApp = CreateObject("word.Application")
WordApp.Visible = True
WordApp.Documents.Open "S:\BOKIS skabeloner\MB.docx"
Dim i As Integer
Dim strValue As String
For i = 5 To 5
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 2)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 3)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 4)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
'bring focus to the document created
WordApp.Activate
'read the value from the cell
strValue = Cells(4 + 1, 6)
'write the value to the document
WordApp.Selection.TypeText Text:=strValue
'move to the next line
WordApp.Selection.TypeParagraph
Next i
End Sub
Regards, MB