Problem using "With Windows" on Word 2007

H

Hans Ruopp

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
 
G

Graham Mayor

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.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Hans Ruopp

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
 
R

Russ

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
 
H

Hans Ruopp

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
 
R

Russ

Hans,
Look at Graham's example more closely.
It looks like you are leaving out the property:
..ActiveWindow

With Leftfile.ActiveWindow
....
 
H

Hans Ruopp

Russ,

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

Regards

Hans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top