Solved

Floating Box Floats too far!

Posted on 2014-02-06
6
150 Views
Last Modified: 2014-02-06
EE Pros,

I have a very nice little macro that byundt built for me that pops up a dialog box that then acts as a button.

Here's the problem, when you open another WB (not WS), the form/dialog box stays on the screen of the new WB.  I need it to stay specifically on the same WS from which it is launched.

Thank you in advance,

B.
Floating-Command.xlsm
0
Comment
Question by:Bright01
  • 2
  • 2
  • 2
6 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39840134
The macro displays a userform and I don't think you can change the behavior that you describe when a userform is used. If you can describe the situation where you want the dialog box to appear, then maybe I can come up with a different way.
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39840258
I think you can accomplish what you are looking for by adding the following VBA code:

This code added to "ThisWorkbook"
Option Explicit
Public FormVisibleInworkBook As Boolean

Private Sub Workbook_Deactivate()
    FormVisibleInworkBook = UserForm1.Visible
    UserForm1.Hide
End Sub

Private Sub Workbook_activate()
    If FormVisibleInworkBook Then
        UserForm1.Show
    End If
End Sub

Open in new window

This code added to "sheet1"
Option Explicit
Public FormVisibleOnSheet As Boolean


Private Sub Worksheet_Activate()
    If FormVisibleOnSheet Then: UserForm1.Show
End Sub

Private Sub Worksheet_Deactivate()
  FormVisibleOnSheet = UserForm1.Visible
  UserForm1.Hide
End Sub

Open in new window


I attached your workbook with those changes made.

Basically the first routine handles the event of changing workbooks, and the second routine does the same thing for when you change worksheets.
Floating-Command.xlsm
0
 

Author Comment

by:Bright01
ID: 39840314
Ken,

I tested it but I still get the Form/Box on the new spreadsheet.

Open the sheet (new) with your code.  Open the Form.  Open a new WB.  You will see the form is now also on the new WB/WS.

What needs to happen is when you open the form, it stays on the original WS.  One way around this may be to put a "change" macro in so that if you move off WS, it automatically hides the form again.  Just a thought.

B.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 39840328
Could you try to explain what you want top do without referring to the existing macro? Or to ask in another way, what is the situation when you want to show the user a message and what do you want him to be able to do in response to the message?
0
 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 39840335
Let's try this one more time...

Looks like I forgot to hit save before I uploaded... so although it was working fine in memory... you did not get the latest version of changes.

(I believe the code I posted was correct.. but it wasn't included in the previous attachment).


@MartinLiss... OP can correct me if I'm wrong... but I believe that the goal is to only show the userform when the sheet that opened the userform is the the activesheet.

So, if you activate a different workbook, or a different sheet, then the userform should be hidden.   If reactivate the original sheet with the form on it... then the form should be shown again.  (but only if it was visible to start with).
Floating-Command--1-.xlsm
0
 

Author Closing Comment

by:Bright01
ID: 39840368
Ken,

Thank you.  Nailed it.  

MartinL,

What I had was the ability to embed buttons within the form and have it come up like a menu of options.  The problem was, it stayed on the screen of other Wookbooks if you had more then one open.  Ken's code, I believe, fixes this little problem.  

B.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question