Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Problem using "With Windows" on Word 2007

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans Ruopp - 23 Jul 2007 11:22 GMT
Hi All,
I use the following command to manipulate an open document with the
following piece of code which works fine on WD2003 but not in WD2007.

“With Windows(LeftName)
       .Activate
       .WindowState = wdWindowStateNormal
     End With”

Where LeftName is defined as ‘String’ and using the step by step mode I
could check that it contained the full name of the file. (Path + filename).

Every time my macro tries to execute this command I get a Runtime Error
'5941': The requested member of the collection does not exist.

Does anyone have already had this kind of problem? I would really appreciate
any help.

TIA

Hans
Graham Mayor - 23 Jul 2007 12:10 GMT
Something like

Dim LeftName As Document
Set LeftName = ActiveDocument
   With LeftName
       .Activate
       .ActiveWindow.WindowState = wdWindowStateNormal
   End With
MsgBox "This is " & LeftName

will work in either version.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi All,
> I use the following command to manipulate an open document with the
[quoted text clipped - 18 lines]
>
> Hans
Hans Ruopp - 23 Jul 2007 15:36 GMT
Thank you for your reply Graham,
I did what you suggested and now I get other error msg (Run-time error:
’438’ Object doesn’t support this property or method) while setting the
window state property.

I have modified the macro to fit your suggestion ‘cause I forgot to say that
the file opened manually in this sub (asterisk in the begin of line shows
what I changed):
First I got the error with “.WindowState = wdWindowStateNormal”, so I
decided to comment it and the error was the same with “.Top = 0”.

It seems that this way I can’t change the properties or do you think that I
made a mistake somewhere.

Thanks a lot for your help and patience.

Hans

The code:

Private Sub Openleft_Click()
 LeftName = MyOpen
 LeftName = ActiveDocument.FullName
 LeftShortName = ActiveDocument.Name
 LeftFilePath = ActiveDocument.Path
 If Right$(LeftFilePath, 1) <> "\" Then LeftFilePath = LeftFilePath & "\" '
Add a Backslah to the end of the path if it does not exist
*  Set Leftfile = ActiveDocument
End Su
---------------------------------------------------------------------------------

Function MyOpen() As String
 Dim a As String
 With Dialogs(wdDialogFileOpen)
   .Show
   a = .Name
 End With
End Functio
---------------------------------------------------------------------------------

Private Sub startbutton_Click()

If (LeftName <> "") And (GloName <> "") Then
  GloForm.Hide
 
  If Not OneSideBox.Value Then
 
**      With Glofile
       .Activate
     '  .WindowState = wdWindowStateNormal
     End With
     With Leftfile
       .Activate
     '  .WindowState = wdWindowStateNormal
     End With
     With Rightfile
       .Activate
     '  .WindowState = wdWindowStateNormal
     End With
 
**      With Rightfile
       .Activate
       .Top = 0
       .Left = Application.UsableWidth / 2
       .Height = Application.UsableHeight
       .Width = Application.UsableWidth / 2
     End With

**      With Leftfile
       .Activate
       .Top = 0
       .Left = 0
       .Height = Application.UsableHeight
       .Width = Application.UsableWidth / 2
     End With
 
  Else
     Leftfile.Activate
  End If
 
  LeftFlag = True

 CustomizationContext = NormalTemplate
 Set MyKeyESC = KeyBindings.Add(wdKeyCategoryMacro, "Left",
(BuildKeyCode(wdKeyEsc)))
 Set MyKeyStop = KeyBindings.Add(wdKeyCategoryMacro,
"GLOSSARY.glomacros.StopRecordingGlossary", (BuildKeyCode(wdKeyControl,
wdKeyReturn)))
 
 RecordFlag = True
 
**  Leftfile.Activate
 
End If
End Sub

> Something like
>
[quoted text clipped - 7 lines]
>
> will work in either version.
Russ - 23 Jul 2007 18:56 GMT
Hans,
One quick thing I noticed is that a function returns its value by setting
the function name to the return value. For example:
Function MyOpen() As String
 Dim a As String
 With Dialogs(wdDialogFileOpen)
   .Show
   MyOpen = .Name ' not a = .Name
 End With
End Function

> Thank you for your reply Graham,
> I did what you suggested and now I get other error msg (Run-time error:
[quoted text clipped - 105 lines]
>>
>> will work in either version.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Hans Ruopp - 24 Jul 2007 17:24 GMT
Hi Russ

Thanks for the tip I already corrected the macro but curiously this function
worked fine. But my main problem still being the change of window property as
I describe above.

Thanks again for you help

Hans

> Hans,
> One quick thing I noticed is that a function returns its value by setting
[quoted text clipped - 6 lines]
>   End With
> End Function
Russ - 25 Jul 2007 07:25 GMT
Hans,
Look at Graham's example more closely.
It looks like you are leaving out the property:
.ActiveWindow

With Leftfile.ActiveWindow
...

> Thank you for your reply Graham,
> I did what you suggested and now I get other error msg (Run-time error:
[quoted text clipped - 105 lines]
>>
>> will work in either version.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Hans Ruopp - 25 Jul 2007 08:06 GMT
Russ,

You're absolutely right. now it works. Thanks a lot for your patience and
valuable help.

Regards

Hans

> Hans,
> Look at Graham's example more closely.
[quoted text clipped - 113 lines]
> >>
> >> will work in either version.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.