Carin
Board Regular
- Joined
- Feb 4, 2006
- Messages
- 224
I'm attempting to run a macro in excel that copies data from named ranges into a Word Document using bookmarks. When running the below Macro, my Word files opens yet no changes are made. I believe it's because it opens in Read-Only mode. I have gone into options and checked and unchecked boxes to trust the document, etc. Can anyone look at my code to see if you can tell why it is doing this? I'm suspecting the code below in blue font, I found this code online to use a name cell with the file location. I'm not familiar with it.
Thank you!
Option Explicit
Sub MyMacro()
'Early Binding by preselecting Tools References Microsoft Word 16.0 Object Library
Dim WordApp As New Word.Application
Dim doc As Word.Document
Dim CTC_N_Received As Word.Range
Dim CTC_N_Validated As Word.Range
Dim CTC_N_Returned As Word.Range
Dim CTC_N_Awaiting As Word.Range
Dim CTC_P_Received As Word.Range
Dim CTC_P_Validated As Word.Range
Dim CTC_P_Returned As Word.Range
Dim CTC_P_Awaiting As Word.Range
Dim docPath As String
WordApp.Visible = True
Set doc = WordApp.Documents.Open([WordPath].Text, , True)
Set CTC_N_Received = doc.Bookmarks("CTC_N_Received").Range
CTC_N_Awaiting.Text = Range("CTC_N_Received").Value
Set CTC_N_Validated = doc.Bookmarks("CTC_N_Validated").Range
CTC_N_Awaiting.Text = Range("CTC_N_Validated").Value
Set CTC_N_Returned = doc.Bookmarks("CTC_N_Returned").Range
CTC_N_Awaiting.Text = Range("CTC_N_Returned").Value
Set CTC_N_Awaiting = doc.Bookmarks("CTC_N_Awaiting").Range
CTC_N_Awaiting.Text = Range("CTC_N_Awaiting").Value
Set CTC_P_Received = doc.Bookmarks("CTC_P_Received").Range
CTC_N_Awaiting.Text = Range("CTC_P_Received").Value
Set CTC_P_Validated = doc.Bookmarks("CTC_P_Validated").Range
CTC_N_Awaiting.Text = Range("CTC_P_Validated").Value
Set CTC_P_Returned = doc.Bookmarks("CTC_P_Returned").Range
CTC_N_Awaiting.Text = Range("CTC_P_Returned").Value
Set CTC_P_Awaiting = doc.Bookmarks("CTC_P_Awaiting").Range
CTC_N_Awaiting.Text = Range("CTC_P_Awaiting").Value
End Sub
Thank you!
Option Explicit
Sub MyMacro()
'Early Binding by preselecting Tools References Microsoft Word 16.0 Object Library
Dim WordApp As New Word.Application
Dim doc As Word.Document
Dim CTC_N_Received As Word.Range
Dim CTC_N_Validated As Word.Range
Dim CTC_N_Returned As Word.Range
Dim CTC_N_Awaiting As Word.Range
Dim CTC_P_Received As Word.Range
Dim CTC_P_Validated As Word.Range
Dim CTC_P_Returned As Word.Range
Dim CTC_P_Awaiting As Word.Range
Dim docPath As String
WordApp.Visible = True
Set doc = WordApp.Documents.Open([WordPath].Text, , True)
Set CTC_N_Received = doc.Bookmarks("CTC_N_Received").Range
CTC_N_Awaiting.Text = Range("CTC_N_Received").Value
Set CTC_N_Validated = doc.Bookmarks("CTC_N_Validated").Range
CTC_N_Awaiting.Text = Range("CTC_N_Validated").Value
Set CTC_N_Returned = doc.Bookmarks("CTC_N_Returned").Range
CTC_N_Awaiting.Text = Range("CTC_N_Returned").Value
Set CTC_N_Awaiting = doc.Bookmarks("CTC_N_Awaiting").Range
CTC_N_Awaiting.Text = Range("CTC_N_Awaiting").Value
Set CTC_P_Received = doc.Bookmarks("CTC_P_Received").Range
CTC_N_Awaiting.Text = Range("CTC_P_Received").Value
Set CTC_P_Validated = doc.Bookmarks("CTC_P_Validated").Range
CTC_N_Awaiting.Text = Range("CTC_P_Validated").Value
Set CTC_P_Returned = doc.Bookmarks("CTC_P_Returned").Range
CTC_N_Awaiting.Text = Range("CTC_P_Returned").Value
Set CTC_P_Awaiting = doc.Bookmarks("CTC_P_Awaiting").Range
CTC_N_Awaiting.Text = Range("CTC_P_Awaiting").Value
End Sub