Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

VBA Queries

  Asked By: Nicole    Date: Sep 30    Category: MS Office    Views: 609
  

I want you help for the following.Kindly tell me how to write codes for
the same

1.When the program/macros are running,the macros in toolbar when
initited by the user show display a message "Macros already in use" and
exit if necessary exit from the application

2.When the program starts,it asks whether to disable or enable the
macros.If the user chooses disable the sheet should be displayed
telling this program will be initiated by macros and must quit the
application.No other sheets should be displayed.If enable is chossen
then the above sheet should be displayed for a second or two then
hide.Then the macros must start.Whether the new sheet should form a
part of the original file .

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Mabel Davis     Answered On: Sep 30

1) You can't start  a new macro when a previous one is running, unless
perhaps if that macro keeps itself active using a timed interrupt. I.e.
there's no point in trying to do this.

2) If the user  chooses "disable" then you're not running  macros, so you
can't take any actions at all. However, you could hide all the other sheets
before saving the workbook. Then, if you disable  macros, that's the one
that will be seen. And if you enable  macros, you can use the auto-open
event to un-hide the other sheets. You can also use the before-save event
to hide the sheets  again before the save.

 
Answer #2    Answered By: Ernesto Robinson     Answered On: Sep 30

I applied it and it worked well.If u any good
VBA program  kindly send me a copy

 
Answer #3    Answered By: Marion Hayes     Answered On: Sep 30

I tried to setfocus in following code but was not sucessful.What is
wrong in the code?Can we use setfocus in VBA or is there any other
fuction.The code is as under

Dim strresponse, ans As String

rt:
If Range("Q1").Value <> "D" Then
Do
strresponse = InputBox("Enter the code of the Division.", "CBRO
Accts")
ThisWorkbook.sea = strresponse
If strresponse = "" Then
MsgBox "Code is compulsory", vbOKOnly, "CBRO Accts"
MsgBox "Do you want to continue", vbyesno, "CBRO Accts"
if ans = vbyes then
setresponse.setfocus
else if ans = vbno then
ActiveWorkbook.Close SaveChanges:=False
End If
Endif
Loop Until (strresponse <> "")

GoTo rt
End If

 
Answer #4    Answered By: Shawna Welch     Answered On: Sep 30

You can't set the focus on a string, which is what is returned by InputBox. Try
this version:

Dim strresponse As String, ans As Integer
If Range("Q1").Value <> "D" Then
Do
strresponse = InputBox("Enter the code of the Division.", "CBRO Accts ")
If Len(strresponse) = 0 Then
ans = MsgBox("Code is compulsory. Do you want to continue?", vbYesNo, "CBRO
Accts")
If ans = vbNo Then
ActiveWorkbook.Close SaveChanges:=False
End If
End If
Loop Until (strresponse <> "")
' ThisWorkbook.sea = strresponse
End If

I couldn't figure out what the line "ThisWorkbook.sea = strresponse" was, but
it looks like maybe you are storing the user's response somewhere.

 
Answer #5    Answered By: Luise Fischer     Answered On: Sep 30

What is setresponse?

Do you have Option Explicit at the top of your module? It will help  you
make sure that everything you're using has been declared.

Also, when you post code, please copy it out of the VB environment. At
least some of this code appears to have simply been typed into the e-mail.

Note that strresponse is defined as variant, not string, because you haven't
given it a type. I recommend that only one item be declared per DIM
statement.

I don't know what "ThisWorkbook.sea = strresponse" is going to do.

You are testing a variable called "ans" but you never seem to set it to
anything. I'd expect that you'd want to set it from your second MsgBox.

Also, you've declared "ans" as a string variable. IIRC vbYes and vbNo are
not string constants.

There are possibly other things wrong with the code too, but I haven't
looked any further.

 
Didn't find what you were looking for? Find more on VBA Queries Or get search suggestion and latest updates.




Tagged: