Print PDF to specific folder with specific name with Excel VBA - excel

I have a folder C:\Users\User1\FolderForPDF, and I have Excel workbooks and a Pdf printer with the name of "PdfPrinter1".
After I edit workbook as I need to, I would like to have a macro, that would print first worksheet in my workbook to PDF. I need it to have a name that is in Cell A1 on this first worksheet, and add "_archive" to that (so eg. "worksheet12_archive"). The PDF should be printed to the folder I listed above. The resolution needs to be set to 600. I want it to go through my pdf printer (not through saving as pdf or printing through Microsoft to PDF).
I would like everything to be set in that "Save as" popup window (suggested name, saving folder).
I know about the .ExportAsFixedFormat and this does the job for me for one other specific thing, but for this one I need it to actually go through printing, because this "save as pdf" makes the resolution way bellow my requirement.
Is that possible to acchive or am I looking at something to much for vba?

Related

"Suggested" File Name when using .Printout in Excel Visual Basic

I am trying to see if there is a shortcut to quicken my workflow.
I have a workbook I have created that runs analyses of given scenarios, and I make a lot of reports that are basically just printouts of a whole bunch of those analyses.
Right now, the workbook is set up to just print out the results by grabbing the two relevant print areas from the two relevant worksheets, and then exporting via the Sheets.Printout Function.
That is reasonably efficient, but when I print dozens of them, it gets a little annoying to type out the full filename (which needs to reference several properties for each one).
I want to set a default filename that just grabs the data from a couple cells and sets that as the name, but I'd like it if that filename populated the entry in the save as window for printing to a pdf, rather than saving to that filename with no input because
I don't always want to use that file name and
I'm worried about forgetting to update the cell entries in the worksheet, and accidentally overwriting old files without noticing.
For example, if I just go through the normal interface and tell excel to "save as", that window pops up with the existing filename already in that interface as a "suggested" filename.
Is there any way to do that with a filename that is derived from values in the worksheet?
Currently, whenever I use the sheets.printout function, the filename entry defaults to a blank value

Adding macro from one excel sheet to another

I'm working with a list of addresses in excel 365. I want to perform a reverse geocode function to produce addresses from the available longitude and latitude info. to do this I have found an excel addin https://github.com/gramener/geocode-excel , which I downloaded. you can see an example in the screenshot above. the formula which it introduces is:
=#NominatimReverseGeocode(B32,C32)
Now what I want to do is make this available in my main sheet so that I can use the NominatimReverseGeocode. I've gone to File - Options - File - Add Ins
But the function 'NominatimReverseGeocode' does not show up in my main sheet. How can I make this function available in my main sheet?
EDIT:
I renamed the file to geocode.xlam in powershell. Now I'm getting:
If your intent is to make the Geocode functions available in all of your workbooks on your computer, do this:
Delete all previously saved Geocode.xlsm and Geocode.xlam files.
Download Geocode.xlsm.
Open it.
Go to File > Save As.
Change the file type from Excel Macro-Enabled Workbook (*.xlsm) to Excel Add-in (*xlam).
Click Save.
Close all instances of Excel.
Open Excel. (i.e. just the Excel application, so not opening a workbook.)
You should be on the Home screen.
Go to New > Blank workbook.
In the ribbon go to Developer > Excel Add-ins.
Check Geocode.
Click OK.
Close all instances of Excel.
Open any Excel workbook or make a new blank workbook.
Put =#NominatimReverseGeocode(51.5,-0.144) in any cell.
This should resolve to the Buckingham Palace Garden.
If your intent is to just have the geocode functions in one specific workbook, let me know and I'll write up the steps for that.
If you only need this code available for yourself and not other users by far the simplest way would be to create a personal macro workbook.
Create a workbook and save it as
C:\Users\username\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.xlsm
Copy the code from the GeoCode workbook into PERSONAL.xlsm.
PERSONAL.xlsm will autoload with Excel. Prefix your function call with the workbook name: =PERSONAL.xlsm!#NominatimReverseGeocode(B32,C32)

VBscript Picture.Insert does not save the picture

I have a VBScript and a method that inserts a picture from a .jpeg file into and excel sheet. I will like for the picture to save to the excel sheet so that when the excel file is sent to another person, they can view the picture.
I have noticed that picture links to the local folder on my computer from which i copied it.
Is there a way to save the inserted picture to be part of the Excel document?
This is my method
set attachment = .Pictures.Insert(path)
The Shapes.AddPicture Method has a parameter to specify whether
To save the picture with the document.
This solution to the same problem replaces .Insert with .AddPictured successfully (German, sorry).

Copy web content from Outlook to Excel using VBA

My client receives an email with a one-time-access url each day (it can only be accessed once, and only on that day).
Content from this url is plain text formatted as a .csv (actually tilda sv) file, but that is not of relevance here.
The content is then (manually) copied and pasted into Excel sheet, where some (formatting) macros are applied (to get rid of tildas and put data into cells).
Also, few of the first rows of the content are irrelevant, i.e. only lines 5-end are copied into Excel.
My question is the following - is it possible to write a VBA in Outlook to
open the url provided in the given email
copy the content from the webpage (and remove those first couple of lines)
open Excel and paste it there (and apply formatting afterwards)
I found some answers on how to copy/paste content from the email itself into Excel sheet, but didn't manage to sort out how to do it from a url/webpage.
Yes it is possible
I am not expert on VBA, but I do little programing to reduce daily task
I can show you the steps:
create rule that triggers VB script when email arrives.
In the VB script in the outlook, write code that would open excel
pass the connection string
set the R1C1 as destination cell
Save the file as date variant .xls
Make sure outlook is open. This would not work if outlook is not open

Use VBA to copy an image from headers/footers of one sheet to another

I need to write a VBA code to copy a company logo in the headers/footers of one excel sheet to another sheet in another workbook. Any ideas?
Excel has a handy Record Macro function.
You can initiate that, Copy the footer over, then stop the recording.
Then, review the code, and it should pretty much show you how to do it.
If you are working in anything older than Excel 2007 then it doesn't sound like this is possible without using the original graphic file (e.g. JPG, GIF etc):
Normally, you can copy and paste the
headers and footers from one worksheet
to another by selecting the worksheets
and then using the Header or Footer
dialog boxes (click Custom Header or
Custom Footer on the Header/Footer tab
of the Page Setup dialog box).
However, if the original headers and
footers contain graphics, the graphics
will not propagate to the other
worksheets. The only way to work with
pictures in headers or footers for
multiple worksheets is to select all
the worksheets, and then insert a
graphic by using the Insert Picture
dialog box (click the Insert Picture
button), or format the graphic by
using the Format Picture dialog box
(click the Format Picture button). The
original graphic file is needed for
this procedure.
source
It may be possible in Excel 2007 - see here
One workaround is to copy the original worksheet to the new workbook:
' macro on the source workbook
Sheets("Sheet1").Move After:=Workbooks("Book2").Sheets(3)
When you do this, you get a worksheet in the destination workbook with all the features of the original, including footers and headers, you can then copy all the content you want into the new worksheet

Resources