Here is a typical example. We are going to open two different word
documents, activate one of the, make some changes by pasting stuff from Excel
into the doc, saving the changed doc, and quitting the application:
Sub playwithword()
Dim App As Word.Application
Dim Doc As Word.Document
Dim emptyy As Word.Document
Set App = CreateObject("Word.Application")
App.Visible = True
Set Doc = App.Documents.Open("C:\Temp\Number.doc")
Set emptyy = App.Documents.Open("C:\Temp\empty.doc")
Doc.Activate
Range("A1:B2").Copy
App.Selection.PasteAndFormat (wdPasteDefault)
Doc.SaveAs ("C:\Temp\Number2.doc")
Doc.Close
emptyy.Close
App.Quit
Set Doc = Nothing
Set App = Nothing
End Sub
Just be sure you have added references to the Word library to the Excel VBA.
--
Gary''s Student - gsnu200793
"AndyC812" wrote:
It still doesn't tell me how to activate a word document, only how to open
one. Is it something like:
Word.Document.Windows(PathToFile).Activate
???
--
Thanks,
Andy
" wrote:
You have to refer to the application that has the program open.
Windows(windowname).Activate would only activate a window within the
active application, which will normally be Excel. See info at the link
below on accessing other programs from within Excel,
http://www.exceltip.com/st/Basic_inf...Excel/462.html
On Jun 23, 11:19 am, AndyC812
wrote:
Hi,
I'm trying to close a particular Word file from Excel without saving
changes. I have the full path to the file in TempFileName variable, this is
what I tried but it is giving me a "subscript out of range" error:
Windows(TempPathName).Activate
ActiveWindow.Close
--
Thanks,
Andy