Free Microsoft Excel 2013 Quick Reference

Running a .exe from VBA

Hi All,

Does anyone know if it is possible (and if so how?) to run a .exe file from VBA in excel? Specifically, I would like to add a command button to my worksheet and when it is pressed it runs a .exe file which is in the same folder as the excel workbook. The .exe file will not be used in any way by excel; it will only display information for the user.

Any help would be appreciated.

Best Regards,

Aaron


Post your answer or comment

comments powered by Disqus
hi everyone,

I wrote a parser in VBA for my excel report. I want my parser running automatically. Does anyone know how to make a exe from VBA, or call my VBA parser from VB code?

Please give me some advice, thanks.

I would need to run a macro, in Excel, from a button in a VBA form. Is there a code I need to enter?

Thanks,

Narfcois

I am running a macro from the private sub code below. The macro I calling for is also stored in the "Objects" area versus the "modules" area--the same place my private sub is located. (Right click on worksheet name, then view code. How do I refer to that place?)


	VB:
	
 Range) 
    If Intersect(Target, Range("a30")) Is Nothing Then 
        Exit Sub 
    Else 
        Call Export 
         
    End If 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
The macro named "export" is executed normally, but the code I'm using--which is basic old stuff--doesn't work like I'm expecting it to. For instance, I get an error message when the macro gets to: Range("o1").Select

I guess the question is can I use regular vba code if my macro resides in the private sub area?

Command.Execute -- running dos commands from vba

after i copy a file to a folder, i would like to:

uncompress it
take off the read only property on the old file
copy in the new file
turn on the read only property

????

thank you....!

Hi Daniel,
What you want to do is turn off screen updating and turn off calculation.

Slow Response, Memory Problems, and Speeding up Excel
Macros run Slow (#slowmacros)
http://www.mvps.org/dmcritchie/excel...htm#slowmacros

Proper, and other Text changes -- Use of SpecialCells
Some notations on the above code, and use of Special Cells
(speed and efficiency considerations) « (#notations)
http://www.mvps.org/dmcritchie/excel....htm#notations
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Daniel" <softwareengineer98037@yahoo.com> wrote in message news:OL4vvWChFHA.272@TK2MSFTNGP15.phx.gbl...
> how do i minimize/maximize a workbook from vba? I want to minimize it
> durring processing to speed things up a bit
>
>

Hi All,

I am trying to run a macro from a UDF but get a error msg: "Expected variable or procedure not module".

Is there a way to get around this or am I doing something wrong.

Hi,

I was wondering if it is possible to run a macro from a cell. That is, if i have a macro which will open a couple of files (like a hyperlink) then is it possible to have some text in a cell "Click here to launch files" which will then run the macro and launch the files?

If all of that is possible, then the further nuisance, is that i have another sheet which uses HLookups to find certain cells, and some of these have links (hopefully these macro-links as mentioned above). If possible, i would also like to beable to use the cell with the Hlookup to load the files (i.e. beable to still run the macro when clicked on).

Hope someone can help,

Regards,

Robert

I'd like to run one of two different macros I have created based on a Yes or
No answer in a cell. I've tryed the following formula:

=IF(K16="No", Macro "Closed", Macro "Not_Closed)

I was just guessing at the command to run a macro from a cell, but was not
correct.

Any help?

Thanks

JIM

Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.

Hello,

A beginners question...

I'm trying to run a macro from a drop down list. (searched the forum in vain)

I've created 4 macros, Macro1, Macro2, Macro3, Macro4

I've have a list of names within A1:A4

A1 is called RunMacro1
A2 is called RunMacro2
A3 is called RunMacro3
A4 is called RunMacro4

A1:A4 has been given a Range name of RunMacro_1to4

I've created a dropdown menue in cell F1 via, Data/Validate/ list, source = RunMacro_1to4

How can I assign The macros to this list?

Thanks for any help

I was wondering if it is possible to run a macro from an if statement . I would be very grateful if anyone could help me with this as it would save me alot of time4 and effort.

Is it possible to run a macro from an IF command?

how do i minimize/maximize a workbook from vba? I want to minimize it
durring processing to speed things up a bit

Hi all, by definition loops fun from the first row and down. I have a set of data that i need to run a loop from the bottom (5000th row) to the top (2nd row).

here is the sample loop that would work if i needed 2nd row to 5000th.

Sub testloop()
    
    Dim cell As Range

    For Each cell In Range("H2:H5000")
        If cell > 3 Then
            cell.Offset(0, 6).Value = cell
        End If
    Next cell

End Sub
so what would i change in this loop for it to run in reverse? from the very bottom to the very top (2nd row)?

ps. does it matter that cell is in all small caps? when i type Cells, it automatically makes it small cap. does that matter at all?

Hi. I am receiving a timeout error when running a SQL query from VBA. Here is the code I am trying to run (I inherited this code and admittedly do not know exactly what each of the commands is doing):


	VB:
	
 
Dim SQLQuery As String 
Dim SQLData As ADODB.Recordset 
Dim FirstDataCell As String 
 
SQLQuery = _ 
"THIS IS THE SQL QUERY I WANT TO RUN" 
 
SQLServerPath = "Provider=SQLOLEDB;" & _ 
"Data Source=MYDATA;" & _ 
"Initial Catalog=MYCATALOG;" & _ 
"Integrated Security=SSPI" 
Set SQLData = New ADODB.Recordset 
SQLData.Open SQLQuery, SQLServerPath, adOpenForwardOnly, adLockReadOnly, adCmdText 
If Not SQLData.EOF Then 
    wks.Range(FirstDataCell).CopyFromRecordset SQLData 
    SQLData.Close 
End If 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
The error occurs on the SQLData.Open line. The error is "Run-Time Error '-2147217871 (80040e31)': Timeout expired"

The SQL query I am trying to run works fine when run directly from the Query Analyzer. I have gotten short queries to work using this code structure, but not longer ones (the error occurs after about 30 seconds).

After searching Help, I have tried the line:

	VB:
	
Application.ODBCTimeout = 0 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
but this did not appear to do anything.

Does anyone have any suggestions?
Thanks!

Hi,

I am currently trying to make my first VBA enhanced spreadsheet. It is basically a spreadsheet that uses 2 lookup tables to find values for use in the building construction industry.

My question is this:

I want to have multiple sheets with information on them and a front page that gives options for each sheet (the options are in the form of buttons that the user simply clicks to do as they wish). One of these options will be to print that specific sheet (each sheet has a row of buttons). This is where I seem to run into problems. Without having a macro for each specific sheet how can I use the button to print out the sheet I want.

The current print macro code is as follows:

Sub print_to_pdf( shtname As String)
Sheets(shtname).Select
Application.ActivePrinter = "CutePDF Writer on CPW2:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("Options").Select
End Sub

From my limited knowledge it appears that you cant pass information to a macro from a button press (i.e. print_to_pdf("Sheet1")) you can only pass a 'flat' macro name (i.e. print_to_pdf).

Is there anyway that I can get the button to A. Pass information to a macro Or B. Have the button return its position when it is toggled (if I knew the positon of which button was pressed then I can work back from that to find out which sheet is needed to be printed).

Any other ways round this problem would be greatly appreciated.

I am using windows Xp and excel 2003

Thanks in advance,
Matt.

Is there example code that shows how to connect to an Access database and
then run a query from excel VBA?

Hi

I would like to run a SQL SELECT on a table from a VBA code, and display the output results in the easiest way. (not on a userfrom etc.)

I prefer not to store the results in an Excel sheet. Just to display it on a separate window if possible.

thanks for any help

Hi

I have a C program that prints to a text file a VB macro that does excel
automation. To run this macro, I need to start an excel app (i.e by going to
START->RUN-->EXCEL ) and then click on TOOLS->MACRO->CREATE NEW MACRO, supply
a name and then copy the contents of the text file (which is output of the
..exe ) and then run the macro. The macro now, operates on a excel file and
saves and closes it. " All this is working fine. "

Is there a way to automtate this task, so no user intervention is required.
Ideally, what I want is:
(1) Launch my C based program , ie. Execute the application
(2) This will now, Create the macro and also RUN it.

My OBJECTIVE In short is:
How do I run a macro from C program ?

Preferably, I would not like to use C# or .NET. my application is failry
simple; and also, I am not not a C# or .NET developer. I have seen some
articles on MSDN but they are not really helpful.
If someone can send me or tell me how to launch a macro from C, that would
be great!
Please bear in mind that I have "NO" knowledge of VB or C#. Some MSDN
examples declare vairalbes that I dont understand at all.

I have a worksheet with a list of Order Numbers in Column A, starting from cell A1. I want to create a macro that will loop through all the Order Numbers in Column A and for each Order Number do the following:

1. Open a file (GenerateReport.xls) in a folder path (C:temp)
2. Input the Order Number into cell C6 of the Data tab in GenerateReport.xls
3. Run a macro (Gen_Report) in GenerateReport.xls (this macro will create a report based on the Order Number in cell C6 and close the GenerateReport.xls file)
4. Repeat steps 1,2,3 for the next Order Number

Would really appreciate any help that I can get as I am newbie to VBA. Thank you!

I am programming by VBA with Excel and I need to execute an executable
application, which is compiled and saved as "Ap1.exe" by other some compiler.

How can I start "Ap1.exe" from a VBA program.
OS: Windows XP,
Application: Excel 2003
--
SUZUKI


hi..

i have a form
i accept some user inputs in the form. there is a link on the form from
where i open the excel file in the same browser (not in a new
page...simply using a href. i am also accepting input from the user in
the excel.

now i want to save the data in excel as well as on asp form.
i can save directly thru vba code in excel to the db. but suppose the
user comes back to the form and somehow doesnt click the submit button
of the asp form to save the data. then it would mean that i saved a
certain piece of data in the db thru excel and the other relevant data
didnt get saved at all!

so i revised my approach. now what i want is that when i click the
submit button on the form i want to save the excel data also.

for this what i am doing is...when i open the excel template i let user
enter data inside it and then i will let him a copy of the excel file on
his machine(cleint machine). so in the end when the user clicks the
submit button i will
1. save the form data in database
2. open the excel file stored in clients machine
3. run a procedure inside it whihc save the data in the db

can i open the excel file on button click on asp form and then run a
macro in the excel file?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Hey folks,

here goes the issue: I was trying to run a module (called from a "Private Sub" in a worksheet) with a variable (target) from that worksheet.

This is the first part (part of my code to call the module) - so far so good:

	VB:
	
 Excel.Range) 
     
    Select Case target.Column 
         
    Case 7 
         
        Filename = Application.GetOpenFilename 
         
        arquivo = Mid(Filename, Len(Application.DefaultFilePath) + 2, Len(Filename) - Len(Application.DefaultFilePath)) 
         
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=Filename, _ 
        TextToDisplay:=arquivo 
         
    Case 5 'target column is "E"
         
        Call mod_Autocompletar.Autocompletar 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
After that it goes to my module named "Autocompletar" (as you could see up here):

	VB:
	
 Autocompletar() 
     
    Dim cel As Range, match1 As Range, match2 As Range, rg As Range, targ As Range 
     
    Set targ = Intersect(target, Plan2.Range("E:E")) 'this is the line where the error occurs - error 424

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
So, the main issue is that after INTERSECT, when I try to recall my target cell, which should come from the previous code in its worksheet, it stops and warns me about the error 424. so, how can I keep the value from "target" from that worksheet in this different module? (I already tried declaring target as a public variable, tried instead of "target", calling the value of that cell by "activecell", but no results...)

(sorry if I couldn't make myself clear... if so, please reply me to try to clarify my point...)

Hi All,
I need to write a code by experts in vb. How can i write a code to run a .exe file. For Eg.

	VB:
	
 BOI_Export_To_Excel_BOIChanges() 
     ' Create Excel object
    Set ExcelApp = excel.Application 
     ' set the Excel propietes
    ExcelApp.Visible = True 
    each_boichanges_report 
     ' kill all instances of Excel
     ' reset the options
    ExcelApp.Interactive = True 
     ' quit
    ExcelApp.Workbooks.Close 'Close all open workbooks
    ExcelApp.UserControl = False 
    ExcelApp.Quit 
    Set ExcelApp = Nothing 
    End 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Here in example Excel application is called. same way i need to create an application for "busobj"

*Note: busobj is the reporting tool installed in my system

kindly guide me

Thanks
santosh


No luck finding an answer? You could always try Google.