|
-
Sep 27th, 2000, 02:31 AM
#1
Thread Starter
Frenzied Member
Hey guys. I want to write a VBA macro in Excel that basically checks if a certain cell has data in it. If so, the program can't close. Also, if possible, if that cell has data in it, the program can't save.
Possible?
Thanks
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Sep 27th, 2000, 08:10 AM
#2
Frenzied Member
Why would you do that? seems to me it would force Excel to be open 24/7... Is that what you're after?
Besides, I don't know if it is possible to prevent excel from closing from VBA, without some nasty hacks.
-
Sep 27th, 2000, 08:46 AM
#3
Lively Member
Take a look at this code
In the example, the program can't close and it can't save if it's data in cells(1,1) of the worksheet 'Sheet1'.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' The program can't close if Cancel=True
Cancel = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' Check your cell here
If Worksheets("Sheet1").Cells(1,1)<>"" then
Cancel = True
End If
End Sub
-
Sep 27th, 2000, 09:55 AM
#4
Thread Starter
Frenzied Member
KWell
that's along the lines of what i'm looking for. but it didn't work. my program saved and closed with data in cell 1,1 (I assume that's A1) of worksheet Sheet1.
Any ideas?
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Sep 28th, 2000, 12:46 AM
#5
Lively Member
Sorry, i forget to tell you an important thing. You must put the code in the 'ThisWorkbook' Microsoft Excel Objects
-
Sep 28th, 2000, 10:48 AM
#6
Thread Starter
Frenzied Member
Well, I'm still a bit hazy about this. I pasted the two into module 1 of the book i'm working on. But when I click Macros on the file menu, they dont show up in any list, all workbooks, this workbook, or any other. Then if I open the VB editor, they're there in Module 1 with my other macros.
Do you have any idea why?
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Sep 29th, 2000, 12:32 AM
#7
Lively Member
The macros i made must be in ThisWorkbook because they are event Word
- Microsoft Excel Objects
| |- Sheet1(Sheet1)
| |- Sheet2(Sheet2)
| |- Sheet3(Sheet3)
| |- ...
| |- ThisWorkBook <-- Here
- Modules
|-Module1
|-...
For the macros show in the macro menu, only public sub (without Public or Private, a sub is public) are visible.
-
Sep 29th, 2000, 03:56 AM
#8
Thread Starter
Frenzied Member
What I mean to say is that I don't know how to put them in the THIS WORKBOOK section. I have never seen any option for this. If I choose Tools>Macros>... I get Module 1.
If I choose to create a macro, and select save in "THis workbook" the name of this sub always returns "NOT A VALID NAME"
how do i select the THIS WORKBOOK for saving those subs?
Thanks
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Sep 29th, 2000, 03:58 AM
#9
Thread Starter
Frenzied Member
KWELL,
SO SORRY.
Geeez. My project explorer window was closed.
Everything works just fine.
Really thanks so much. ANd thanks for your patience.
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|