Jump to content
Macro Express Forums

Printing Files...


patgenn123

Recommended Posts

Does anybody know if one could print a file without having to open it? Suppose I have a database that could launch a playable macro that could print a file without opening it. Can it be done?

 

 

 

 

Also, can multiple files be appended to print together? In other words, suppose I have a folder that I want to print two files, but all I want to do is highlight them and then for example hit a hot key or right-click/hit print/ and it prints out without having to open them. can this be done with Macro Express?

 

Any suggestions would help!

 

Pat

Link to comment
Share on other sites

When an application prints information from a file it performs a certain amount of processing on that file. The program must be running before you can print.

 

You should be able to automate the steps of launching the database program, printing the file, and closing the database program. Another forum discussion talks about accessing a database via Macro Express. You can view that discussion here.

Link to comment
Share on other sites

I think Kevo thinks you are trying to print a report or something that is in a Db without opening the Db but I think you’re talking about printing a file from a Db form. For instance there maybe a text file somewhere on the file system and you want to use a macro to grab some info from the form or table and print that file, am I right?

 

If it is the case there are many applications that can print from a command line but not all. If they are simple text files you can simply copy them to a printer port in most cases. But most applications will require a command with a switch. For instance I have a client with hundreds of thousands of PDF (Adobe Acrobat) files and I often need to print thousands at a time for a mailer. Most applications are easy and have something like a “/p” switch where you specify the EXE, switch, then file name you want printed. But some like PDF are more tricky. I spent an entire afternoon one day but finally came up with a reliable way to print PDFs from a “Launch Program Only” command in ME. If it’s PDF you’re after let me know and I’ll hook you up with it.

 

For other applications check out the programs documentation or look online. But here’s a cool trick. Look at the file associations in the system for the extension you’re looking at. You know, open an explorer window, Tools>Folder Options>File Types and find your extension. Once you find it hit the advanced button. Usually there will be a default “Open” action for when you double click the file but there will often be alternate right click options like “Print”. For instance in my system I have PDF print:

 

"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe" /p /h "%1"

 

The %1 will be the file name and you can see the switches are /p for print and /h for “hidden”. Simply steal this and pop in your own variables. In my case this wasn’t enough because I needed to be able to specify a non-default printer but that’s just more command line code. But I think you get the idea.

Link to comment
Share on other sites

Thanks for the info Cory and Kevin! If you have that info available Cory, I would like to learn about it.

 

I could start by understanding how to print a file(.pdf,.doc,.xls etc) on my desktop.

 

For simplicity sake, is there anyway of printing a file without having to open it just by highlighting it and maybe hitting a shortcut key to just print it? I know what the file is all about if I name it properly and I really don't need to open it to print it, just print it!!!

 

From there, I could use the macro to put the macro in a launch line in the database from a button to execute the macro to print that file. It's not a template, it's just a file I want printed.

 

In a paper intensive business, after the deal closes, the boss wants the docs in order to file away. After I learn how to do this, I can have the macro call up the documents(which has been already scanned in) and just print them in order when the button pressed and the order the macro calls them up based on the customer's name. All without having to open them! Viola! Order to the business and fast hole punching of the docs!

 

Of course I could have macros call multiple print jobs that way too, but I don't want them to be opened to print. i don't need to.

 

Thanks!

 

Pat

Link to comment
Share on other sites

I’ll look up that info here when I get a chance on how to do PDFs. Hmmm… might be another write up for my web page… But if you don’t need to specify a different printer other than your default the command I gave you will work.

 

Here’s the trick: In ME the “Launch Only” command will work just like the “Run” line above your start button. Assuming you’re still on XP. Experiment with that and once you got it down in there use that ‘run’ command in the Launch command. Then substitute variables where need be. Super simple.

 

is there anyway of printing a file without having to open it just by highlighting it and maybe hitting a shortcut key to just print it?
Of course, this is what I described. In Windows right click the file and choose “Print”. Now strictly speaking it does run the program but it usually does it in some minimized or hidden way. And it will only print to the default system printer.

 

Although I advocate ME for most everything (Still can’t get it to make coffee yet) you might want to consider using a macro in the Db app. If it’s access you can write macros (VBA) that can do a lot of this sort of thing. For instance I am creating a button in my Access Db that will launch an explorer window in the client’s folder. It takes the name and ID can applies some substitution rules and launches the folder. However you may be more comfortable using ME if you want to do things like repeating and such. I know I am a complete newb on VBA so I’m relying heavily on others for that.

Link to comment
Share on other sites

Cory,

 

OK. I think I got it. Now let's suppose I have a folder byt the name of "Smith".

In this folder, all files are there for Mr. Smith in which all file names begin with the word "Smith" and so on.

 

How can I create a macro and pull Smith's docs in order to which I set it up in the macro to print without having to open docs to print and also include any .doc/.xls(in other words, any file type) to the printer also?

 

Where do I start? What do I do? Keep in mind I am not trained in computers, but trying to learn everyday. Be gentle. Speak in plain English... :blink:

 

Thanks!

 

Pat

Link to comment
Share on other sites

Plain English is a second language for me so forgive me if it doesn’t come naturally.

 

pull Smith's docs in order to which I set it up in the macro

 

I’m not sure what order this is. Do you have some sort of rule? For the moment let’s assume you just need to print them all in alphabetical order. We can add more logic later if necessary.

 

Let’s say they were just PDF files for the moment. I would do a “Repeat with folder”. This is a simple looping procedure what will return every file name in our folder in alphabetical order to a variable. Now use that file name to create a print command. It might look like this:

 

Repeat with Folder
 Program Launch: "Acrobat.exe""
Repeat End

 

<REP3:07:000002:000001:0001:0:01:c:\clients\smith\><LAUNCHDEL2:0:01"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe"<PARAM>/p /h "%T1%"3 ><ENDREP>

You can copy the above and paste it directly into the ME scripting editor.

 

Simple eh? But you want to specify the folder yourself? OK, then add a prompt for folder name.

 

<TVAR2:02:10:What folder do you want to print? ><REP3:07:000002:000001:0001:0:01:%T2%><LAUNCHDEL2:0:01"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe"<PARAM>/p /h "%T1%"3 ><ENDREP>

 

Check out our post on getting the folder name by using the right click option too.

 

But you have multiple file types? Well then just add a condition test.

 

Variable Set String %T2% from Folder Name
Repeat with Folder
 Variable Set From File Path
 If Variable %T3% = ".pdf"
   Program Launch: "Acrobat.exe""
 End If
 If Variable %T3% = ".doc"
   Program Launch: "WINWORD.EXE""
 End If
Repeat End

 

<TVAR2:02:10:What folder do you want to print? ><REP3:07:000002:000001:0001:0:01:%T2%><VFFILE:1:F:1:F:1:F:1:T:3:%T1%><IFVAR2:1:03:1:T .pdf ><LAUNCHDEL2:0:01"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe"<PARAM>/p /h "%T1%"3 ><ENDIF><IFVAR2:1:03:1:T .doc ><LAUNCHDEL2:0:01"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"<PARAM>/p "%T1%"3 ><ENDIF><ENDREP>

 

I don’t know what the command line switches are for Word so I just took a guess at it. You need to research that yourself. Anyway you can see here that we did the Varible Set From Path to set T3 to the file extension. IOW an acrobat file will be “.pdf”. Then if T3 is a “.pdf” it uses that command line. See how this works?

 

I didn’t actually test this macro and I’m sure the “Program Launch” parts will need to be fixed but this should give you a basic idea. Play with that and get you command line switches (parameters) working in ME and then we can go from there.

Link to comment
Share on other sites

Cory,

 

I am having some issues. First, I have Acrobat 7.0(2). Second, it is opening up a clean(no images) acrobat file(with a gray background). Third, it is saying "There was an error opening the document. This file cannot be found" I used your macro that opens the explorer window to choose a file.

 

The program path for 7.0(2) is: "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe". I replaced what you had in the launch line to this path.

 

Any idea what is wrong?

 

Pat

Link to comment
Share on other sites

Whoa, no wonder. I had that all screwed up. Like I said I didn't try it, I was only trying to give you an idea of the structure. Try this:

<TVAR2:02:10:What folder do you want to print? ><REP3:07:000002:000001:0001:0:01:%T2%><LAUNCHDEL2:0:01"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"<PARAM>/t "%T1%" "hp officejet g series"><ENDREP>

 

In my example I had the command line parameters from Word mixed in with the PDF. In this example I don't check if it's a PDF so make a test folder with only PDFs to test. Your path to Acrobat obviously works so I used it in the example. IOW you don't need ot fix it.

 

On my XP machine I discovered that the job did not go to my default printer as I told you. That was based on a Windows 2000 Pro machine. In fact I have no idea where it went! Might ahve to look into that. So I had to explicitly state the printer name and you will ned to modify where it says "hp officejet g series". Go to your printers folder and copy the name exactly as it appears there.

 

This could be a problem if the macro is distributed to several machines so I'll have to check into this one day.

Link to comment
Share on other sites

My example with the different conditons for different text types went all haywire. I just tried pasting it back in and it's broken in the first "If". Try using this one instead:

<TVAR2:02:10:What folder do you want to print? ><REP3:07:000002:000001:0001:0:01:%T2%><VFFILE:1:F:1:F:1:F:1:T:3:%T1%><IFVAR2:1:03:1:T .pdf ><LAUNCHDEL2:0:01"C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe"<PARAM>/p /h "%T1%"3 ><ENDIF><IFVAR2:1:03:1:T .doc ><LAUNCHDEL2:0:01"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"<PARAM>/p "%T1%"3 ><ENDIF><ENDREP>

I just have the one for PDF and it it works fine. You can add more Ifs for other document types.

Link to comment
Share on other sites

Cory,

 

Thank you! The first one works, but the last(the Winword one) post does not.

 

Also, the 2nd last post(the one that works) minimizes the file in the bottom tray. Is there any way to make the print clean and not have it minimized? To not even show up, just print? Does Windows have to have it active to print?

 

Pat

Link to comment
Share on other sites

Dang, I pasted in the same thing again! Sloppy, sloppy. I'll try once again...

 

But in the mean time check out what Kevin was saying. Almost all data files are in some proprietary format and with rare exception the printer does not understand this format. When an application prints it creates a file in a format the printer understands. For instance a word doc is in Word's format. If you copied it to a printer you would get digital guacamole. Word converts just the graphics you want to a file in a format dictated by the driver. For instance HP's PCL (Printer Control Language). Think of it this way... You can have a color photo and print it in BW, right? Well the data is much different between the two printer files because you choose a different output configuration but the source file is the same, isn’t it? Back when I worked in Engineering Documentation and before the advent of formats like PDF we actually saved the plot files in HPGL so one didn't require AutoCAD to get a drawing. Then we had clever little programs to copy the files to printer ports for the buyers when they requested them.

 

So you need to run the application in order to generate this printer file. About the only file type that doesn’t is plain ASCII text files.

 

What the /t does is launch the program quietly (minimized) and not prompt the user for print settings.

 

There may be some way to get it to launch without blipping in the taskbar but that’s beyond me. But in my experience it’s a non-issue.

 

I was just trying a couple of things and found one of the stupid little problems. Actually there are a couple. I’ll be updating my web page for these. One problem is that if Acrobat is not open the document remains open. I remember now I had it launch Acrobat first then fire away. Strange behavior.

 

Oh, you don’t need to specify the entire path to Acrobat. I was using simple “acrobat.exe” with not problem.

 

I’ll get back to you in a second.

Link to comment
Share on other sites

I updated my web page for printing PDF. It's good to get that done. In trying stuff for your post I began to remember allthe problems I ran into and realised the need to record them all someplace. http://bluepointdesign.com/macros/PDFPrint.htm

 

Here's the code that I meant to paste in last time. I checked it to make sure it worked this time!

 

<TVAR2:02:10:What folder do you want to print? ><REP3:07:000002:000001:0001:0:01:%T2%><VFFILE:1:F:1:F:1:F:1:T:3:%T1%><IFVAR2:1:03:1:T.pdf><LAUNCHDEL2:0:01Acrobat.exe<PARAM>/t "%T1%" "printer name"><ENDIF><ENDREP>

 

Check out on my web page about using a batch file instead of the Launch Program command to avoid the flow control issues.

Link to comment
Share on other sites

Wikipedia page on batch files

 

Batch files are simple text files that run commands one would normally type into a command (DOS) prompt. If you don't know what this is we might be getting in a little deep for you. But if you want to learn how to do batch commands it might be worth your while to learn.

 

Do you have any experience with command (DOS) prompts? You know, that little back window that pops up when you go Start > Run and type in “command”? Well if not there is bunches of stuff you can do in a command prompt like copying files and such. For instance you could type in “copy myfile.txt a:” and it would copy the file to your floppy drive. If you know a little about this then batch files shouldn’t be too difficult for you.

 

With that PDF file we could type that command from my web page into the command prompt and your PDF would print. And if we create a batch file with several lines of these they would all print consecutively. And you wouldn’t have to use them just for PDF’s, it could be for all file types. So what one would do is create the batch file using the Variable Modify Append to Text File command (with CRLF) and the run the batch file. Then of course you would need to delete the file.

Link to comment
Share on other sites

By adding another If condition for .DOC, .XLS, and so on you can have it run a different command line for each file type since their command line switches need to be different.

 

I was just looking at Word and there isn’t a command line switch for printing. It appears that it uses DDE and I’m not sure how to make that work. But you can call a Word macro from the command prompt so you could do something like this example IO found on some guy’s web page.

 

Sub PrintNow()

Documents.Open FileName:="D:\_temp\test.doc"

Application.PrintOut FileName:="D:\_temp\test.doc"

Application.OnTime Now + TimeValue("00:00:05"), "Quit_Word"

End Sub

 

Sub Quit_Word()

Application.Quit

End Sub

 

But then again it might be easier to have ME do it.

 

I know one can print a Word doc by right clicking on it and I see all the DDE stuff in there but I don’t know how one can use DDE from ME. I’m sure there’s a VB Script that one could use instead but it would take a little research to find. Might be a subject for a new post. There are a few guys here that are pretty keen on VB Script that I’m sure could help.

 

I’d love to see a solution as I am sure I will need it one day but I just don’t have the time to research it now. Sorry.

Link to comment
Share on other sites

Cory,

 

I got it! Wow I feel useful now!

 

Here is how it would work with Word...

 

"C:\Program Files\Microsoft Office\Office\winword.exe" "G:\My Cabinets\Pat G\Inbox\Pat.doc" /mFilePrintDefault

 

This is exactly how it runs on the "RUN line and it works! So Now the variables have to be added if it needs to repeat through a folder etc..

 

I am going to see how this works with PowerPoint Excel etc. Someday I might be dangerous with computers!

 

Pat

Link to comment
Share on other sites

I'm guessing you're dangerous now but in a different way. ;)

 

Hey that's a great trick for printing. I'll need to make a note of that. I knew /m was the macro switch but I didn't know there was one for printing like this. Does it close Word as well?

Link to comment
Share on other sites

  • 2 weeks later...

I am trying to print an unnamed document. What happens is the document is a tempate that has not been named yet and when the database opens the template the title bar has the words--"Document1-Microsoft Word". The only difference between the template and a blank instance of Word, is that the template shows the merged fields etc.

 

How can I get this to automatically print with a command print switch using Macros? I tried everything.

 

You can't put Microsoft Word in the Program Path/ Name because the database launches the instance and pops up the template. I don't know what to put there. I tried setting value to Window AND setting value to program assigning it to %T1%, putting %T1% in the Program Path/Name, but it seems to not work.

 

How can I get Macro Express to work with silent print command line switch for Word:

 

"C:\Program Files\Microsoft Office\Office\winword.exe" "G:\My Cabinets\Pat G\Inbox\Pat.doc" /mFilePrintDefault

 

and have it work for an unnamed file? If I have to name the file, then how could I rename the Word file without have to go through File|Save As|Save file Name and have the clumsy process for saving a file work its way through?

 

Also, I have a system figured out on how to rename the file with text type command. So that's not an issue.

 

Is there an answer for either issue?

 

Pat

Link to comment
Share on other sites

You can not use the command line trick for a file that only resides in memory. It needs to reside on disk someplace. To silent print in Word don’t you just click on the printer icon?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...