I have a Tiff file splitter DLL that has a VBA code:
Dim tsplit As New SCTiffPageSplitNetDLL.TiffPageSplitterDLL
Dim rslt as Integer
To call the function and split TIFF files, you could use the following:
rslt = tsplit.Tiff_PageSplit("C:\test\test.tif", "C:\outputdir")
MsgBox rslt
How can I run this line of code in a command prompt? I need to make a batch file(.bat) out of this code.
You could put it in a VBScript (.vbs) file and run it using cscript. See this thread How to run a .vbs from a .bat
Related
I am writing a macro for a Solidworks PDM Task.
I have manage to write into the script in the Task, that it should start a specified macro. This works.
In the macro I would like to open a PcSchematic file (.pro) and the run a .cmd file, which will ask PcSchematic to convert the file into a PDF. And then close the program.
I am novice in VBA - I have found and edited this macro, which opens PcSchematic, but not the file and I don't know how to proceed.
Sub Auto_Open()
Dim x As Variant
Dim Path As String
' Set the Path variable equal to the path of your program's installation
Path = "C:\Pcselcad\Pcselcad.exe"
x = Shell(Path, vbNormalFocus)
End Sub
Right now we use a Dispatch to do the trick, with a Shell execute:
Where the commandline says: C:\Pcselcad\Pcselcad.exe "%PathToSelectedFile%" C:\ODIN\administration\Dispatch\SaveAsPDF.cmd
This method is working, but it is not closing down the PcSchematics when it is done. And I would like to start it with a task, which gives me some other benefits, this is why I want to do it with a macro.
I was trying to execute a batch file via standard call shell() function.
This Batch file is project specific and created automatically for each project by an external application. Main function is to normalise around 40 files having statistical data used for my project. This data is being acquired form excel. While executing manually this takes around 30 seconds for the complete process and its working just fine.
When I try to access this using call shell function in VBA, It just pop up for like 2 seconds and outputs were not generated from Batch file.
I am attaching My sample code below used for this. I am just baby-stepping in VBA Macros. Please Excuse my coding practice.
Call Shell(Range("L8") & "\DSTAT$.BAT")
I tried this also
`Dim Runcc
Runcc = Shell(Range("L8") & "\DSTAT$.BAT", 1)`
Please let me know if any further information is required to sort this out.
Try
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
With CreateObject("WScript.Shell")
.Run Range("L8") & "\DSTAT$.BAT", windowStyle, waitOnReturn
End With
I use this for converting PDFs to JPG with Irfanview on report_open in Ms-Access.
Stolen from vba WScript.Shell run .exe file with parameter
I want to call a .reg File out of my VBA script. I'm using Office/Excel 2013.
I know Excel can't run these files by itself, so i need to call the file via shell. The code i wrote doesn't work:
Sub deactivateHyperlinkWarnings()
Dim x
x = Shell("cmd /C C:\TEMP\DisableHyperlinkWarnings.reg")
End Sub
I found this piece of code somewhere on the web, but its not working. I don't even get an error message. The .reg File is located in C:\TEMP
What do i need to write to make it work?
Plus: Is it possible to suppress the MessageBoxes that are displayed when i run the .reg-File? When i start the file manually, i need to Hit "OK" like 3 Times. The people who are working with the Excelsheet later on shouldn't be seeing these things.
Instead of running cmd try to run reg. So in your case it should be x = Shell("reg import C:\TEMP\DisableHyperlinkWarnings.reg")
More info here
I have a macro in VBA (Excel 2007).
It opens an exe file with entering a HEX value as variable.
The exe gives the output (also a HEX number).
I do everything with "shell" command and the results is saved to a txt file. Then I write this to Excel.
retVal = Shell("cmd.exe /c C:\AABB\app.exe 0x5110 > C:\AABB\output.txt", vbNormalFocus)
It is complicated and time-consuming.
I would prefer getting the result directly to Excel, without an intermediate file like txt or similar.
When I use an output.xlsx as output destination, the file is created and the value is written. But I cant read it with Excel. I see the value when I open the xlsx with Notepad.
My questions are:
1) Is it possible to write the result directly to xlsx, especially a target cell e.g. A10
2) Why when I use xlsx as destination in shell command, I can't open it with Excel? It gives Error Message of "file-format or file-extension is not valid. Data might be corrupted".
I think you can't do that with shell object.
you can do it with WSHExec with the function StdOut.ReadLine().
You have to go to reference and choose "Windows Script Host object model" so you can declare a WshExec object. than see the Method yourWshExecObject.StdOut.ReadLine().
To construct WshExec :
First declare a WshShell Object and you construct it like that :
Dim WshShellObject as WshShell
Dim WshExecObject as WshExec
Set WshShellObject = New WshShell
Set WshExecObject = WshShellObject.Exec("your .exe filename").
The WshExecObject.StdOut TextStream will read everything you write in the console.
I did it with an .exe compilated with C++.
You can also use WshExecObject.StdOut.ReadAll to read all lines at once.
Hope that helps.
Why does a batch file run when I create it in Notepad, but not when I create it in my VB code?
Dim strStartFile As String = "C:\Documents and Settings\All Users\StartMenu\Programs\Startup\Starter.bat"
If Not File.Exists(strStartFile) Then
Dim strBatLine1 As String = "cd C:\Progra~1\Applic~1 && start Application.exe"
My.Computer.FileSystem.WriteAllText(strStartFile, strBatLine1, False)
SetAttr(strStartFile, FileAttribute.Normal)
End If
It creates the file just fine. It looks exactly the same as the handmade version, it just won't launch the exe when double clicked. I've tried appending CR+LF, vbCrLf, but no go.
There is an inherent problem when trying to launch the exe directly from Startup, it runs it from that directory and can't find the related files (in the Application directory) so the cd is necessary.
Using VB 2010 Express. Thanks in advance for your help!
You probably need to pass in the Systems ANSI CodePage, because you are executing the file from cmd.exe
My.Computer.FileSystem.WriteAllText(strStartFile, strBatLine1, False, System.Text.Encoding.Default);