ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close a particular Word file from Exce; (https://www.excelbanter.com/excel-programming/412985-close-particular-word-file-exce%3B.html)

AndyC812

Close a particular Word file from Exce;
 
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

[email protected]

Close a particular Word file from Exce;
 
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



AndyC812

Close a particular Word file from Exce;
 
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




Gary''s Student

Close a particular Word file from Exce;
 
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





All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com