What is the Bug in the below code? [closed] - vba

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have written
sub main ()
'some code goes here
end sub
This is the Module that I defined in the sheet1.And Yes I have only one workbook opened and in the userform1 I have given a command button Ok and when ok is pressed , The main function in sheet1 should be called
sub CommandButton1_Click()
call sheet1.main
end sub
I have tried these The problem Iam facing is , The code works sometimes and sometimes throws an error saying that an undefined object or not set with Occured.Why the code is working for sometimes and not for sometimes? Do i need to make any changes to make it work everytime ? Thank you in advance

The one thing I've found that makes my VBA programming easier is to always fully specify the object you're trying to manipulate (well, except maybe the top-level Application).
That means you should use something like Workbooks(0).Worksheets("Sheet1").main instead of relying on the active workbook.

Related

How can i make my own command to my first console application in VB.NET? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm doing my first VB.NET console application. I have some experience making VB.NET "non-console" applications.
My guestion is, how can i make my own commands to my console application. For example if user types to console "Hello World" and then the application would answer back to the user. I dont want it to be like "Press any key to continue..." nothing like that. I just want to make my own commands.
I've already tried to find some help from YouTube or Google but i couldn't find anything that would help even little. So i'm asking from you guys.
I also would like an answer soon as possible.
Console.ReadLine will block execution until the user has pressed the enter key. It then returns the full string of whatever the user typed on that line. You can then write conditional code which acts on whatever that returns. So, for instance:
Dim input As String = Console.ReadLine()
If input = "Hello World" Then
Console.WriteLine("Hello to you too")
End If

Execute two VBA macros simultaenously [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is it possible that 2 macros can be executed simultaneously in VBA.
So there will be one macro which will take inputs from a database in access and will continue to show the data like a news strip. That code I have made.
Now there are other data and charts also on the same sheet. The problem is can the user execute the other macros for changing the data/Charts on the same worksheet by pressing command buttons or selecting radio buttons while side by side the film strip like data continues to flow on the screen.
Thanks.
No. VBA is single-threaded. Thus, one task must complete before another can run.
You can fool it by using Shell to launch an external process, but that's another story.

Run program that is not in the same folder [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need some help here, thanks, I am currently making a project in VB.net. What I want is that when you press a button, it will launch a program. So let's say that my program is called "test.exe" and the file is placed in "C:\Users\user\desktop\test.exe". How do I attach a code to a button that will RUN this program? Thankyou so much. Sorry if this is a bad question.
Use this code:
Public Sub Btn_Click(sender As Object, e As EventArgs) Handles someButton.Click
Process.Start("C:\Users\user\desktop\test.exe") 'You can also pass arguments by overloading this method like:
Process.Start("C:\Users\user\desktop\test.exe", "foo argument")
End Sub
use Process.Start("C:\Users\user\desktop\test.exe", "Arguments here")
UPDATE
if your main.exe is in xyz folder and your test.exe is in folder outside xyz say abc then use
Process.Start("xyz\..\abc\test.exe", "Arguments here")
This is relative path Note that both xyz and abc have same parent

VBA errors not popping up when the code fails [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I know this is probably a little backwards but in this case I want the errors. I am working on a project and I am no longer getting pop up run time errors in VBA. The code just stops and I have to go step by step to find it. I must have done something to make it stop doing this but I have no idea what it was.
Any suggestions?
Best regards, CK
I can think of Three reasons
Close and reopen the excel file. Ensure that before you re-open there is no left over instance of Excel in task manager.
You are using On Error Resume Next
Incorrect Error Handling

Copy whole sheet to another VBA [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm looking for a vba macro that copy whole data inside a sheet to another creating the new sheet. For example; I have a sheet called 14.11.2013 with some values.. clicking a button i need that the macro creates the new sheet and copy the entire datas from 14.11.2013 sheet to this one new. I'm a beginner in vba so i don't have much idea how can i do this kind of work. Someone can help me?
Of course when everything is copyed i want redirect in the new sheet.. I think something like:
Sheets("NewSheet").Activate
Here is the general format:
Sub CopySheet()
Dim s As Worksheet
Set s = Sheets("14.11.2013")
s.Copy after:=s
End Sub
If you are looking for some beginner tutorials i would recommend ExcelVBAIsFun on youtube.
I believe this video will help with how to record macros and teach yourself how to do some of the more simple things in Excel VBA. It also does something very similar to copying from one sheet to the other.
http://www.youtube.com/watch?v=HmAYKyurYNU&list=PLw8O1w0Hv2ztGjIkrW7suD6oNDaOk3vbR
I used this quite a bit while learning VBA myself.