christosf360
New Member
- Joined
- Apr 19, 2015
- Messages
- 8
Hello everyone, I have been trying to do this for the past 2 days!!!! I have spent a lot of time here looking at various posts and I have tried to pick up bits and pieces to make this macro work, unfortunately I am not successful.
The task is this: I need to past various cells (ones that are not blank) from column E in XL into different bookmarks in Word.
I have this code below (copied from a post from this site) that will open the Word document but then anything I try with locating the bookmarks fails, any advice would be much appreciated:
The task is this: I need to past various cells (ones that are not blank) from column E in XL into different bookmarks in Word.
I have this code below (copied from a post from this site) that will open the Word document but then anything I try with locating the bookmarks fails, any advice would be much appreciated:
Code:
Dim TestRange As Range
'Declare obj variables for the word application and document.
Dim WdApp As Object, wdDoc As Object
'Declare a String variable for the example document's name and folder path.
Dim strDocName As String
'On Error statement if Word is not already open.
On Error Resume Next
'Activate Word if it is already open.
Set WdApp = GetObject(, "Word.Application")
If Err.Number = 429 Then
Err.Clear
'Create a Word application if Word is not already open.
Set WdApp = CreateObject("Word.Application")
End If
'Make sure the Word application is visible.
WdApp.Visible = True
'Define the strDocName String variable.
strDocName = "C:\Test.docx"
'Check the directory for the presence of the document name in the folder path.
'If it is not recognized, inform the user and exit the macro.
If Dir(strDocName) = "" Then
MsgBox "The file UC372" & vbCrLf & _
was not found in the folder path" & vbCrLf & strDocName, _
vbExclamation, _
"Sorry, that document name does not exist."
Exit Sub
End If
'Create the Word document from the template.
Set wdDoc = WdApp.documents.Add(strDocName)
Run "OP"
'Release system memory that was reserved for the two Object variables.
Set wdDoc = Nothing: Set WdApp = Nothing
Last edited by a moderator: