Solved

Floating Box Floats too far!

Posted on 2014-02-06
6
147 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now