Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Macro to Close Word File dwake Excel Discussion (Misc queries) 3 December 3rd 09 02:04 AM
printing Exce 2007l spreadsheets from Word 2007 cynwalker Excel Discussion (Misc queries) 0 August 6th 09 04:18 PM
default font in Word and Exce 2007? Debbie Excel Discussion (Misc queries) 1 September 3rd 07 08:48 PM
Excel caluclation setting reverts back to manual when I close Exce mm1861 Setting up and Configuration of Excel 4 August 22nd 05 07:17 PM
How do you keep a comment close to the cell it relates to in Exce. EHN Excel Discussion (Misc queries) 1 April 18th 05 07:47 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"