![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
I've created a userform in ExcelXP-VBA to enter data. There is some code in the userform module to control some behavior. I need to pass the result of a MsgBox to the main worksheet module for further processing. The following are the key code snippets:
Userform Module Private Sub WriteDataReponse = MsgBox("blah blah", vbYesNo) UserForm1.hide End Sub Worksheet Module Public WriteDataResponse Private Sub WriteResponseData = vbNo Userform1.Show If WriteDataResponse = vbYes Then WriteData1 = Userform1.TextBox1.Text WriteData2 = Userform1.TextBox2.Text End If End Sub I thought a Public variable would be avaiable in all modules and its value preserved. I've set a couple of breakpoints and monitored WriteResponseData in the Locals window. WriteResponseData sets to vbYes (value 6) in the Userform module as it should. When I check the Locals window in the Worksheet module, WriteResponseData is still set to vbNo (value 7). It stays this way when the Userform subroutine ends and control is returned to the worksheet module. I don't get it!! Help! TIA, ...Eric |
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Are you putting it in a Worksheet module ? or in a regular module ?
Try putting it in a standar module. |
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
I don't think I understand the difference. The modules I seem to have available are:
VBAProject.Sheet1 VBAProject.Userform1 Is there something else I should be doing? I've got the nagging feeling I'm doing/not doing something fairly stupid for this to be fighting me so much!! TIA, ...Eric |
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Yes, you should put it in a Module1, not in the Sheet's module, why ? because Sheet's module are Private Modules. Standard modules aren't (Unless you make them)
|
|
|
|
|
|
#5 |
|
Guest
Posts: n/a
|
YES! YES!
Thank you sooooo much!! ...Eric |
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|