I am currently using ShellExecute to print a PDF using the below code.
The PDF is being printed alongside other (Word) documents. However, I need them to print out in a specific order, which is a problem because the PDFs take longer to be sent.
Is there a way to check if the PDF was sent to the printer before moving on to the next line of code?
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
ShellExecute Application.hwnd, "Print", formPath, 0&, 0&, 0&`
Lots to read here, and honestly, above my skill set, but it looks to answer your question.
It may also be as simple as just checking the count in the printer queue. If the previous file was a .PDF, then only print the next file if the queue count is equal to zero.
Printer Queue Count...
http://visualbasic.happycodings.com/applications-vba/code9.html
Tons of printer options...
http://www.merrioncomputing.com/Programming/WatchPrinter.htm
Related
I'm using VBA (MSAccess) to print the contents of a folder using ShellExecute. It works perfectly, except for the small detail of printing in color.
Private Declare PtrSafe Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As LongPtr, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) _
As LongPtr
I'm calling the function like this:
ShellExecute hwnd, "print", ToPath & "\" & file, 0&, 0&, 0&
As I said, everything works exactly as I want it to, except that the print jobs are only printing in grayscale. I really need this to print in color. Does anyone have any idea of why this is only printing in grayscale?
I'm trying to print a .pdf file using a shell. The printout comes from the default printer, but I would like to do it in the mode without opening Adobe Reader, I would like it to be invisible to the user. I tried to use the "SW_HIDE" variable but at this point the printout does not come out at all. I will be grateful for your help.
My code:
Const SW_SHOWNORMAL = 1
Const SW_HIDE = 0
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Dim PrintIt As Long
PrintIt = ShellExecute(Me.hwnd, "print", "C:\Test.pdf", "", "", SW_SHOWNORMAL)
'Pdf1.src = "C:\test.pdf"
'Pdf1.printAll
End Sub```
If I understand the question correctly, you want to use a headless PDF printer so the user does not know which application is doing the printing.
Looks like Adobe does not allow this and doing this could violate their license:
https://community.adobe.com/t5/acrobat-sdk/how-to-print-a-pdf-programmatically-without-the-adobe-reader-window/m-p/4343967
Most important – have you read the Acrobat Reader EULA to ensure that
your use is compliant? Many batch and headless operations are not
compliant with the EULA.
If you do not have to use Adobe Reader, there are a number of other PDF printer applications that allow silent installation and headless printing.
http://www.columbia.edu/~em36/pdftoprinter.html
https://www.biopdf.com/
https://www.coolutils.com/TotalPDFPrinter
https://www.bullzip.com/products/pdf/info.php
Evening Everyone -
I'm looking for some thoughts on how to read / write values from a windows "ini" structured file. I have a settings file created with another application and I would like to update values of a key within a specified section. I got it working using a buffer.replace process but now realize that some keys are used over in sections and globally replacing a value will cause problems.
Here is a sample of what my ini file looks like
IMPORT-1]
SETTINGS="HELLO"
FILENAME="C:\TEST\TEST1.CSV"
[ENCODE-2]
FILENAME="C:\TEST\REPORT1.XPS"
I've got dozens of blocks so any clarity on accomplishing a read and write of a value within a specific section would be hugely appreciated!
--Cheers & Thanks
George
You can use some of the kernel32 functions.
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
This will let you read an ini file
Dim sb As StringBuilder
sb = New StringBuilder(500)
GetPrivateProfileString("IMPORT-1", "SETTINGS", "", sb, sb.Capacity, "test.ini")
I am stuck on a really stuck with this one line. In vb.net this is easy, but how do I do this in vb6? Tried to search from google for few hours and got nothing. Feels almost embrassing.
Here's the code. (.NET)
Process.Start("runme.exe", " -parameter1 " & "-parameter2 " & "-parameter3")
I want to run EXE, from the same directory as where the program is, with parameters. I am sure there is some very simple solution, but I can't get it to work. Any help would be appreciated.
You can use Shell and ShellExecute
Shell "c:\runme.exe", vbNormalFocus
http://msdn.microsoft.com/en-us/library/aa242087(v=vs.60).aspx
Just call Shell, and the parameters should be passed also with the string of the .exe name, like this:
Call Shell("""runme.exe"" ""-parameter1 "" ""-parameter2""", vbNormalFocus)
PS: The quotes make the difference, dont ignore it :)
You can use ShellExecute for this:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
ShellExecute 0, "open", App.Path & "\runme.exe", "-parameter1 -parameter2 -parameter3", vbNullString, vbNormalFocus
I have found that using Shell causes a delay in the calling program waiting for the return value, whereas ShellExecute does not.
When I call a rebol script with
call shell("rebol.exe myscript.r")
The shell doesn't return until the script is finished. Is there a way to force VBA Shell to be asynchronous ?
If you just want to use Shell function, try another option with using API :
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
This is the full code of ShellEx function :
http://www.vbaccelerator.com/codelib/shell/shellex.htm
You'll want to pass in a second argument to make the program run in the background. Here's the documentation.
call shell("rebol.exe myscript.r", vbMinimizedNoFocus)