Solved

Floating Box Floats too far!

Posted on 2014-02-06
6
149 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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