I am trying to use excel data to perform various tasks on a word document. However, this will be used by other people, so I wanted to copy all contents from the word doc (and formatting and tables) to a new word doc and edit the new one to prevent others from accidentally saving over the first one (template one). I also want to close the template (first) doc and keep the second (new) one open.
I am new to VBA and am having trouble understanding how to handle this. After a bunch of googling, I've compiled this (not working) code:
Dim WordApp As Object
Dim WordDoc As Word.Document
Dim NewWordDoc As Word.Document
'Dim other stuff'
'-------------------------------------------------------------------
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open("C:\Users\Windows\Documents\CRC Labels
test.doc")
Set NewWordDoc = WordApp.Documents.Add 'I think this gives an error'
'------------------------------------------------------------------------
'Line that actives WordDoc'
Selection.WholeStory 'Select whole document
Selection.Expand wdParagraph 'Expands your selection to current paragraph
Selection.Copy 'Copy your selection
'Line that closes WordDoc'
'Line that activates NewWordDoc'
Selection.PasteAndFormat wdPasteDefault 'Pastes in the content
'------------------------------------------------------------------------
'Do stuff with NewWordDoc'
'------------------------------------------------------------------------
Set WordDoc = Nothing
Set WordApp = Nothing
Any other ideas of handling this situation? Thank you for your response.