LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default UserForm updated


Thank you so much Dave!!! The code works great ...It will really save me a
lot of efforts!!! God bless you and compile successfully!
"Dave Peterson" wrote:

First, the sheet events are limited to events that happen on that individual
sheet.

Workbook events are limited to events that happen on that individual workbook.

So what you'll need is an application event--things that happen any place in the
application.

You can read more about application events at Chip Pearson's site:
http://www.cpearson.com/excel/AppEvent.aspx

Chip uses a different technique (a dedicated class module) and the following
uses the ThisWorkbook class module.

This seemed to work for me (in simple testing). I created a simple
userform--just a textbox. I can close it via the X at the top right corner of
the userform.

First, create a new general module in your workbook with the userform.

Put this code in it:

Option Explicit
Public UF1IsLoaded As Boolean
Public UF1 As UserForm1
Sub ShowTheForm()
If UF1IsLoaded Then
'do nothing
Else
Set UF1 = UserForm1
UF1.Show vbModeless
UF1IsLoaded = True
End If
End Sub

Then this is used in the Userform module:

Option Explicit
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
UF1IsLoaded = False
Unload Me
End Sub

And finally, this is used in the ThisWorkbook module:

Option Explicit
Public WithEvents xlApp As Excel.Application
Private Sub Workbook_Open()
Set xlApp = Application
Call ShowTheForm
End Sub
Private Sub Workbook_Close()
Set xlApp = Nothing
If UF1IsLoaded Then
Unload UF1
UF1IsLoaded = False
End If
End Sub
Private Sub xlApp_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)
If UF1IsLoaded Then
UF1.TextBox1.Value = Target.Cells(1).Text
End If
End Sub

Save this workbook (a test workbook????).

Then run the Workbook_Open event (manually or by closing and reopening the
workbook).

And test it to see if it works.



Dan Tabla wrote:

Can anyone please help me with following code?

I cant make this code work on all opened Excel Workbooks.
I only succeded on the workbook that contains the UserForm1, which contains
text box txtLayout.

I put this code under "ThisWorkbook" and it runs nicely but only localy on
the sheets included on this workbook.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

UserForm1.txtLayout = ActiveCell.Text

End Sub


--

Dave Peterson
.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel cells randomly don't get updated unless each cell is updated Lost in Excel Excel Discussion (Misc queries) 5 September 29th 08 06:56 PM
Userform to have Last Updated Values Time & Date Displayed ?? Corey Excel Programming 2 December 14th 06 03:15 AM
updated row comes at the top Fam via OfficeKB.com Excel Discussion (Misc queries) 2 April 11th 06 05:20 AM
links are not updated Alex Excel Programming 0 March 10th 06 12:45 AM
Link not being updated.... brian ferris Excel Discussion (Misc queries) 1 May 3rd 05 02:08 PM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"