VB code to print a file from a third-party application to a network drive without dialogue box - excel

I have a specific requirement in our organization.
We are using a third-party tool to convert excel to pdf. Our excel files contain financial data and charts and the tool converts them to pdf files. Once converted, they are sent for printing.
Now I need to write a vb code which tampers with the printer configuration. After conversion to pdf, when I click on print in the tool, it should not go to default printer to print the physical file, nor should it display the dialog box asking for printer to choose, rather it should pop-up a custom dialog box indicating file being saved in the network drive. The drive and file name should be pre-configured.
I know there are quite a few solutions which caters to this problem of saving a file without displaying the default dialog box but my problem is, I am not printing files from the same application. Files are prepared by a third-party application and print option is pressed from here itself. When the file leaves for printing, I want my code to take effect. In a way, if this application is configured in a computer, no matter which tool you are using to print, the files should get saved to a network drive without popping up the default print dialogue box.
Thanks in advance. Any guidance is much appreciated.

Related

How to open a file from an absolute path without having to save a copy

So we have our local website to navigate through our drive :
showcase of the website
Here, each button is a link to something on our drive
One of which is a link to a Excel file :
showcase of that specific link
Now, that Excel file contains relative links to PDFs : Relative links inside an Excel
If we click on that button linked to that Excel file from Edge (2nd screen), a prompt appears asking if we want to "Open" the file or "Save as", but the issue is... if we choose "Save as", obviously the links inside that Excel file wont work (unless we save it at the same location), so that's totally normal, the correct option would be to "Open" it.
The problem is that opening a file from Edge... actually doesn't open a file at all, it saves it locally under the AppData path of our machine and THEN opens it.
That means even in that case, the paths inside our Excel file wont work either because they are relative.
I know one solution would be to change all links to absolute links inside that Excel file, but that is a tedious work (because there are a LOT of links, we would have to create a script or something to do that).
So my question is, is there any way to directly open that Excel file from the path specified in the button's link, instead of saving it first locally under "C:\Users\XX\AppData\Local\Temp\MicrosoftEdgeDownloads\f02875af-f436-47bb-b7e5-f3caa96df03f" ?
This is not an issue when using Internet Explorer.
Thank you in advance for any help.
Kind regards,
If you want to allow intranet zone file URL links from Microsoft Edge to open in Windows File Explorer, you can try this Edge policy: IntranetFileLinksEnabled.
Otherwise I don't recommend you to do this, based on the security issues already mentioned.

Retrieve data from server and operate a GUI

I just want to know if this is possible using VBA, if it is possible, I will try to code it and if not I should look for another platform where it is possible.
Let me explain:
We have 1 main excel file. There`s a header name and a bunch of different values and settings we need to use.
We have a online server where the code has to look for the header name and just click on the name. This will automatically download to the download folder and we can copy this file in the same folder as the main excel file. There is no search function inside the online server. It is just a webpage where there is a list of names.
Inside the downloaded file is an xml file that we can open with notepad and we need to compare the settings inside the notepad with the settings from the main excel file (this I know it can be coded)
Then a GUI has to be opened (we dont have access to the server behind it), it should fill in the header name in the textbox from the GUI, click upload and then it should save it in the same folder as the main excel.
we also need to move a lot of folder based on the info from the main file but this is also basic coding.
Since Im quite new with the VBA coding, I only wish to know if this is possible in excel. I dont want to wast time searching for codes and then realize it is not possible , especially with the GUI operating.

Manage external data source locations in Excel when sharing the file across Dropbox

When working in Excel, sometimes we have external data sources.
In Windows, these files may be stored in a specific location such as C:\Users\Freelensia\Dropbox\data source.xls
When sharing the main file and the data source file with another person through file-sharing services such as Dropbox, the location of the data source will be changed to:
C:\Users\PeterSmith\Dropbox\data source.xls
(from the view of the Peter Smith user)
This will break the data connection in the main file when Peter opens it. He can reset the path to the one as seen from his computer, but that will break the connection for the Freelensia user when he/she opens it from his/her end.
Is there a way to permanently fix these locations for multiple users? Such that Excel will correctly get the path when the right user opens it.
I am looking for an inherent Excel property if such a thing exists. Else VBA macros (A table with the file paths for each user, and MsgBox that ask the user to choose the user profile). Else a Windows .bat file could work as well.
Thank you for your help.
A trick to this is to move your Dropbox to C:\Dropbox for all users.
To do that, click on the Dropbox icon at the bottom-right, click the Gear Icon, Settings, Sync Tab, then you can move the folder to C:\Dropbox.
If you encounter permission errors, follow the instructions here to reset the permissions:
https://www.dropbox.com/help/desktop-web/move-dropbox-folder
If my understanding is right when ever a different user opens/saves a file the path "C:\Users\xxxxxxx\Dropbox\data source.xls" will be same only "xxxxxxx" in the path will be varying with the active user who has logged in.
So use "Application.UserName" function to get the username and use it in the path mentioned above
Excel uses relative links, even though it shows longer paths in the cells when you look at them. This ends up meaning that if you move the file and the file(s) it is connecting to a different location then the links will still work.
If you put your main file in Dropbox\Excel\main.xlsx and then your data sources in Dropbox\Excel\Data\data sources.xlsx then I think you should be good.
I tested this with Google Drive on two different computers, taking turns opening and modifying the data source and also opening and having the main file update without any issues.
I am not positive if this would work for you in Dropbox, but I really think it should... I am using Excel 2010, so if you are using Excel 2003 (or saving files as .xls instead of the newer .xlsx format) there is a possibility that could cause issues.

Print to PDF is different in excel depending on custom DPI

I was called in this morning to work on a tool that I had built in Excel a while back. The tool generates a report and then prints it to a pdf. The problem they called me in for was that for one user the line spacing in the PDF was off. It took me a while to figure out the cause of the problem. It was the DPI. The user who has trouble seeing the font had increased the font of Windows to 150% and for some reason that causes excel to export to pdf differently.
I know what the problem is but asking the user to change the DPI (forcing the user to log off), log back in, open excel and run my macro and finally change back the DPI is not a reasonable solution. I hope that there is a guru out there that will be able to help me find a solution. I don't mind adding VBA code to temporarily change the DPI while the program is running but I'm not sure how to do that or if its possible.
Thanks
For more clarification its windows 7 and the aspect I’m speaking of is if you go to change the resolution there is a link asking if you want to “Make text and other items larger or smaller”. The slider was changed from the defaulted 100% to 150%.
I cannot think of an easy way of overcoming this problem. Something that you could try is to create an OLE application (in C#, VB.NET or C++ for example) that uses Excel internally just to open the file and export it to PDF. Then you can create a new user on the system and lunch this application from a batch file using the command runas.
Back in Excel again, you can lunch the batch file using the Shell command.
The workflow would be:
1- Using VBA and the Shell function,invoke the batch file from Excel with the current file as parameter.
2- The batch file calls a custom application MyAppExportToPDF using runas and passes the current Excel file as parameter.
3- MyAppExportToPDF opens a new instance of Excel using OLE, loads the file, and exports it to PDF.
Since MyAppExportToPDF will run in a different user, the new Excel instance should also run under that user. The DPI settings under this user should be the ones you need.
Disclaimer: This is just an untested idea.

How to print from excel to pdf without typing in a filename

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.

Resources