I have a number of questions on this topic:
If I print using Application.ActivePrinter = "Microsoft Print to PDF on Ne01:" then how can I pass a specific file name and path to the printer? (Rather than having it prompt me?)
Since I want others to use this file, how can I check that Microsoft PDF is always on Ne01? What if theirs is on a different port?
Many suggest using a Findprinter command, but I always get the sub or function not defined error
Many suggest using the built-in ability to save as a PDF, instead of printing to PDF, but I find the resulting PDF has huge margins and the wrong size (not A4)
You can save Excel sheets as PDF directly. Try below macro. Change C:\ to save your file to your desired location.
Sub SavePDF()
Dim pdfName As String
pdfName = "MyFileName"
Sheets("MyPDFsheet").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\" & pdfName & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=True, _
OpenAfterPublish:=False
End Sub
PDF printouts go to a "Port" that port can have a filename same as any printing device. The user normally is tasked with select device/folder/portname.pdf thus there is a virtual PORTPROMPT: device (that is set via the print prompt dialog)
A) Set a duplicate driver to a port as a fixed filename in a watch folder. see Print to PDF with powershell while suppressing the "Save As" Prompt and https://stackoverflow.com/a/69169728/10802527
A) You cannot, this Windows 11 just Like Other Windows versions currently does not have an MS PDF printer, it is a windows optional extra I am not allowed to install.
A) Too variable, Default 1st NEtwork printer may be a Fax or in this case nothing so should return NULL
A) Save should have options. see https://superuser.com/questions/1064214/create-pdf-from-an-excel-file-without-white-margins for other suggestions, However for PDF Print there are many reasons for no fixed size, Windows will keep changing printers to "last used" unless told other wise, and last used can be any paperkind or margins.
However, In my case I frequently set default to my region (A4 Portrait) and as often as I can I set "No margins" but windows Edge will frequently reset that to big "Default". Perhaps I should set default to A4zerOmargin
Related
I'd like to have a script that I can run where it basically takes the .rdp file that I have selected in finder, and append a line of text to the end of it.
e.g
I download a .rdp file to use in Microsoft Remote Access and to speed up my workflow I'd like to append the text 'Use Multimon:i:1' at the end before I launch it so that I don't have to open the preferences each time.
I'm not too familiar with AppleScript so would appreciate any advice on how to achieve this.
Thanks!
It is my understanding that .RDP files are saved in plain text format. If this is the case, using the do shell script command in an AppleScript, appending text to a file is fairly simple. This following AppleScript code should work for you.
Paste this following code into a new Script Editor.app document. Then
with your .RDP file currently selected in Finder, run the code in Script Editor.app and it will append the text to your file.
property addText : "Use Multimon:i:1"
tell application "Finder" to set selectedFile to POSIX path of ((get selection) as alias)
do shell script "echo " & quoted form of addText & " >> " & quoted form of selectedFile
This currently works for a selected file with the extension 'txt'. Test it and if it works for you, edit it to your desired extension.
The 'if' statements are to ensure that you don't accidentally append the text to a binary file which could corrupt that file. The 'return' means that your text will appear on its own line. If you don't want that, remove 'return & '. For details on 'open for access', please see the Language Guide: Commands Reference. On the same page, you can find 'close access'.
tell application "Finder"
set tFile to selection as alias
if name extension of tFile is "txt" then
set corR to true
else
display alert "Are you sure you've selected the correct file?"
set corR to false
end if
end tell
if corR is true then
set ab to open for access tFile with write permission
write return & "Use Multimon:i:1" to ab starting at eof
close access ab
end if
I have an excel file with the script that allows me to generate seperate pdfs according to the data i enter into one spreadsheet. However, the code was created using Windows, and I would like to use it in mac. Can anyone help with changing the pathname of the script? The script is as follow:
Sheets("6 comp").Activate
Range("$I$93").Value = i
ActiveSheet.Calculate
ClientName = Range("$I$94").Value
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\test\" & ClientName & "_6", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Thank you so much!!
Unfortunately, it's not as easy as changing the filename path in this case.
I stripped out the specifics to your situation and got it to work fine on Windows. But when I first ran it on my Mac, it send the PDF right to my default printer instead of saving the file to any location.
Consistently, any attempt to edit the script on my Mac resulted in Runtime Error 1004 (even after changing back to the original code). I believe this is a bug, but there are also a lot of unsupported features on the Mac, and many are not documented by Microsoft.
Ron de Bruin's website for Mac/Windows Office topics has a great writeup on how to save a PDF in Excel Mac. http://www.rondebruin.nl/mac/mac005.htm If you really need to get this working, that page should help.
I'd much prefer to give you a straight answer, but if you look at that page, you'll see how complicated it is.
I have a very old VBA file that was created by someone else with limited comments to explain it. The file is a training file that asks for names, and then supplies the file names you can view to train in. Variables are passed around from 5 different subroutines.
RetVal = Shell("C:\Program Files\Microsoft Office\OFFICE11\PPTVIEW.EXE " & ProgFile, 1)
This is the line that opens the PowerPoint 4.0 files from Excel. ProgFile being a passed variable.
My Problem: If I put the files in directory on the C:\ drive (Say C:\Training\Forklift.ppt) the file opens fine and the program does what it is supposed to do.
HOWEVER: Putting those same PPT files on my network Drive (S:\Training\Forklift.ppt) I get three error messages as pop-ups NOT coded into the program (I suspect System errors). (Path names were changed to show as S:\
PowerPoint Viewer Cannot find the File RECORDS
PowerPoint Viewer Cannot find the File Safety
PowerPoint Viewer Cannot find the File Forklift.ppt
RECORDS and Safety are NOT files being used by any of the subroutines. Is it because of the Shell Function to open PowerPoint or some other mystical thing I am overlooking?
I am trying to rewrite the Subroutines and this is part of the unchanged code that is giving me issues.
try surrounding your arg in quotes:
RetVal = Shell("C:\Program Files\Microsoft Office\OFFICE11\PPTVIEW.EXE " & Chr(34) & ProgFile & Chr(34), 1)
My guess is that RECORDS and Safety are both some sort of external files that are linked in your Forklift.ppt presentation. PowerPoint is notorious for breaking presentations when things get moved. If there are any links in the PPT, they will need to be updated to point to the new location on your S: drive.
You can automate changing the links by writing some VBA code for it, but if this is a one-time move, it's probably not worth it - just redo them by hand.
I have a folder with about 4000 image files. I need to select some of those files, based on whether their names appear in an excel spreadsheet, and copy them to a new folder. If possible, I would also like to tag them with a color tag so I know which files in the original folder were moved and which were not. I got the code below from here.
tell application "Microsoft Excel"
tell worksheet 1 of active workbook
set fileList to value of used range
end tell
end tell
set rootFolder to "path/to/sourcefolder" as POSIX file
set filesToMove to {}
repeat with thisItem in fileList
try
set end of filesToMove to alias (rootFolder & thisItem)
on error
display dialog "File " & thisItem & " is not in the folder"
end try
end repeat
tell application "Finder"
move filesToMove to folder "path/to/destination" as POSIX file
end tell
When I run it, it's unable to find any of the files. I think the issue might have to do with using / in my file path instead of : but I don't know how to set a path to an external drive with the applescript syntax. Using the same variable declaration, set rootFolder to "path/to/sourcefolder" as POSIX file, and then telling finder to open rootFolder works fine.
I also need the script to have more flexibility - not all files have the same naming conventions, and so I need it to search for any files whose names contain the identifiers from the spreadsheet, but may not match it exactly. I.E. the spreadsheet entry may be "00103", but the file name is "PX00103KL.jpg."
In the meantime, I've created an automator workflow that moves and tags the files exactly the way I want, but only after I manually enter the search string. If I could combine those two ideas, of iterating through the spreadsheet entries in excel and using each in turn as input for the automator workflow, that would be ideal.
Thanks for any help!
I don't have Excel, but assuming that you can get a list of strings from it, here is a bit of code that will find all files in a target folder that contain the string(s), set a label to it and then copy it. Change appropriately.
It uses the unix command line tool for spotlight, mdlist to find the files. Trying to do it purely in applescript seems to be painful. The shell command when stitched together is something like this:
mdfind -onlyin ~/Documents/ "kMDItemDisplayName == '*somestring*'"
Here is the code:
set stringList to {"144", "g_"}
set rootFolder to "/Users/blah/Downloads/" as POSIX file
set destFolder to "/Users/blah/Downloads/test" as POSIX file
set filesToMove to {}
set mdAtr to "\"kMDItemDisplayName == '*"
repeat with thisItem in stringList
set sPath to quoted form of POSIX path of rootFolder
set sName to mdAtr & thisItem & "*'\""
set sCmd to "mdfind -onlyin " & sPath & " " & sName
set sResults to (do shell script sCmd)
set fList to (every paragraph of sResults) as list
repeat with i in fList
set f to (POSIX file i) as alias
tell application "Finder"
set label index of f to 3
#copy file f to folder (destFolder as alias)
end tell
end repeat
end repeat
Is there a way to get around having to type in a filename when sending a document to Adobe PDF printers? My code is:
Application.ActivePrinter = "Adobe PDF on Ne01:"
MyWorkbook.PrintOut From:=1, To:=3, Copies:=2, Collate:=True
This works except that it prompts me for a filename. Would rather find a way to fix this without installing any extra libraries so it would be portable.
Thanks
Does this help at all?
"How To: Changing the Adobe PDF
Printer/Distiller Printer Settings"
"Issue
You wish to automate printing from a
third party application to either
Adobe PDF or Distiller print drivers
so that no UI elements are invoked for
example 'Do not send fonts to
Distiller', 'View results in Acrobat',
'Prompt for PDF Filename', 'Delete log
files for successful jobs', and the
'Ask to Replace existing PDF file'
preferences when you print.
Solution..."
I had to solve a similar problem where I had to create PDFs with automatically-generated file names.
In my solution, I installed PDF Creator, which acts like a printer on your computer, except that it saves PDF files when you print to it. One of its settings allows you to automatically save a PDF to a directory when you print to PDF Creator.
I set up my Excel application to print repeatedly to PDF Creator. I can't remember which it was (perhaps the name of the worksheet?), but one of the sheet's properties controlled the title of the document and thus the name of the saved file.
This isn't an ideal situation because it requires you to manually toggle a setting in PDF Creator, but it worked very well for a simple application I ran on my own machine.