PC Review


Reply
Thread Tools Rate Thread

Close a particular Word file from Exce;

 
 
AndyC812
Guest
Posts: n/a
 
      23rd Jun 2008
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 With Quote
 
 
 
 
chip.gorman@gmail.com
Guest
Posts: n/a
 
      23rd Jun 2008
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 <AndyC...@discussions.microsoft.com>
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 With Quote
 
AndyC812
Guest
Posts: n/a
 
      23rd Jun 2008
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


"(E-Mail Removed)" 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 <AndyC...@discussions.microsoft.com>
> 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 With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      23rd Jun 2008
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
>
>
> "(E-Mail Removed)" 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 <AndyC...@discussions.microsoft.com>
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does Word close when I close a file? =?Utf-8?B?S3dhbGl0eWd1eQ==?= Microsoft Word Document Management 14 8th Nov 2006 09:12 PM
Why does Word close when I close a file? =?Utf-8?B?S3dhbGl0eWd1eQ==?= Microsoft Word Document Management 0 26th Jun 2006 07:00 PM
Excel caluclation setting reverts back to manual when I close Exce =?Utf-8?B?bW0xODYx?= Microsoft Excel Setup 4 22nd Aug 2005 07:17 PM
How can I keep Word from closing every time I close a Word file? =?Utf-8?B?ZW1tZXR0Z2liYnM=?= Microsoft Word Document Management 3 16th Aug 2005 02:16 AM
How do you keep a comment close to the cell it relates to in Exce. =?Utf-8?B?RUhO?= Microsoft Excel Misc 1 18th Apr 2005 07:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.