UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Trying To Activate A Window In A Macro, Office 2013    
 
   
baffled100
post Jan 2 2018, 05:04 PM
Post#1



Posts: 371
Joined: 10-December 12



Hi,

I recorded a macro and it errors out on the line where I am trying to close one of the documents (the merge document, but leaved the merged document open) with this error message "Requested Member of the Collection Does Not Exist". The file does exist and is still open but the macro doesn't think it exists, so therefore it doesn't get closed......why doesn't it work?? Is there another way to close a document in a macro? Thank you!

Windows("Board depart ltr merge FRI [Compatibility Mode]").Activate
ActiveWindow.Close
Go to the top of the page
 
Doug Steele
post Jan 2 2018, 07:03 PM
Post#2


UtterAccess VIP
Posts: 21,552
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Does this work any better?

CODE
  Windows("Board depart ltr merge FRI [Compatibility Mode]").Close

--------------------
Go to the top of the page
 
baffled100
post Jan 2 2018, 08:10 PM
Post#3



Posts: 371
Joined: 10-December 12



Thanks for your reply! Unfortunately, using your statement has the same result. It errors out on that line with the same error message.......
Go to the top of the page
 
cheekybuddha
post Jan 2 2018, 09:47 PM
Post#4


UtterAccess VIP
Posts: 9,407
Joined: 6-December 03
From: Telegraph Hill


Is '[Compatibility Mode]' part of the name of the document?

Have you tried:
CODE
Windows("Board depart ltr merge FRI").Close


Otherwise, try enumerating the window names:
CODE
Dim i As Integer

For i = 0 to Windows.count - 1
  Debug.Print Windows(i).Name
Next i


Then use the correct key,

Note, I didn't test above - .Name might not be the right property, and I don't know whether Word is 0 or 1-based

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
baffled100
post Jan 3 2018, 12:47 PM
Post#5



Posts: 371
Joined: 10-December 12



Thanks for your reply! [Compatibility Mode] is not part of the document name, when I recorded the macro, that is how it listed the document name. I did try it without--"Board depart ltr merge FRI" and also tried "Board depart ltr merge FRI".docx . Same results.

I'm not sure how/where to do your other suggestion..... iconfused.gif
Go to the top of the page
 
Doug Steele
post Jan 3 2018, 01:19 PM
Post#6


UtterAccess VIP
Posts: 21,552
Joined: 8-January 07
From: St. Catharines, ON (Canada)


I'll jump in for a minute and correct David's air-code. (The Windows collection is 1 based, not 0 based, and it's the Caption property you want, not the Name property):

CODE
Dim i As Integer

For i = 1 to Windows.Count
  Debug.Print Windows(i).Caption
Next i

That being said, it looks as though you cannot refer to the window by its caption, so rather than

CODE
Windows("Board depart ltr merge FRI [Compatibility Mode]").Activate
ActiveWindow.Close

try

CODE
Dim i As Integer

For i = 1 to Windows.Count
  If InStr(Windows(i).Caption, "Board depart ltr merge FRI") > 0 Then
    Windows(i).Close
    Exit For
  End If
Next i


--------------------
Go to the top of the page
 
cheekybuddha
post Jan 3 2018, 01:48 PM
Post#7


UtterAccess VIP
Posts: 9,407
Joined: 6-December 03
From: Telegraph Hill


Thanks Doug for filling in the bits I was too busy lazy to test!

wink.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
baffled100
post Jan 4 2018, 03:24 PM
Post#8



Posts: 371
Joined: 10-December 12



Thanks to you both--I was able to figure out the issue......I re-saved the documents without 'maintaining compatibility' and now the code in the macro works as it should. smile.gif
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    20th January 2018 - 10:27 AM