Solved

Floating Box Floats too far!

Posted on 2014-02-06
6
146 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 45

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 45

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

18 Experts available now in Live!

Get 1:1 Help Now