Solved

Floating Box Floats too far!

Posted on 2014-02-06
6
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 47

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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