VBA Word Toggling Between Open Documents

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
190
This is driving me bat-sh*t crazy!

I have a button on a userform that I want to toggle between two open ms word documents. So when I press the button, I want the document that is not active to be the active document on the screen. This is my code:

Private Sub CmdLink_Click()

If CmdLink.Caption = "Link" Then
Windows("UserLink (Read-Only) [Compatibility Mode]").Activate
ActiveWindow.Panes(1).Activate
CmdLink.Caption = "Main"
ElseIf CmdLink.Caption = "Main" Then
Windows("UserMain (Read-Only) [Compatibility Mode]").Activate
ActiveWindow.Panes(1).Activate
CmdLink.Caption = "Link"
End If

End Sub


It changes the caption on the button like it's supposed to, but as far as changing the window -- it does nothing. If I eliminate it down to it's simplest:

Windows("UserLink (Read-Only) [Compatibility Mode]").Activate
ActiveWindow.Panes(1).Activate

It still does nothing. The window doesn't change at all. I'm 150% positive the names of the files are in their correctly. Any ideas on what the problem might be?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,225,609
Messages
6,185,981
Members
453,333
Latest member
BioCoder84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top