Save Excel templ;ate as PDF

Hello all,

I have a process I’m working on and I have one piece left to get working. I want to open a Template I created in Excel, paste in the variable AWB and then save it as a PDF. I have that working but the output is corrupt so I need to try another way. What’s the best way to save as PDF? I can think of

  1. Use the recorder - is this possible with variables? If so, how?
  2. Use Send Hotkey F12, Type into with the folder & file location, and Click Text and use Click Down to get to the Save As option of “PDF”

I don’t know how to do either of these. Can someone tell me how to do whichever is easier?

Thank you

Hi there @mworth123

Here are a few things you can do…

  1. UiAutomation - Click Save as -> select PDF format from the drop-down and then click ‘save’ button (I do not recommend this)
  2. Send hotkey F12 - that opens the ‘Save As’ window and do the remaining steps. (Easy but you will have to put in retries if the hotkey fails at the first attempt)
  3. Or use a simple script either Invoke VBA or invoke code or even an excel macro. (Pretty much guaranteed to run - haven’t faced any issues when I run a script.)

I can give you a very simple script that can convert excel into a fixed format PDF. Hope this helps.

Dim workbook As New Workbook()
workbook.LoadFromFile("C:YourRelativePath\ExcelName.xlsx")

workbook.activesheet.ExportAsFixedFormat xlTypePDF, "C:\YourName.pdf"

Store in variables the excel path and the directory of the pDF save file patha nd check wheter the file was converted/created successfully and also you can overwrite it using the inbuilt option.

Get back if you have any issues.

@Raghavendraprasad - Thank you, I’m a beginner so option three seems out. Option one is not recommended so that leaves option two.

Option two - I’ve created the Send hotkey F12 and the Type Into activities and the text in the Type Into looks like this:

“Z:\Disposal Letters”+strAWB

Then I have a Click Text activity and the ClickType is CLICK_DOWN and I’ve set the Occurrence field to 24 to arrow down to where the PDF file type is located in the drop down.

Will this work? Right now I have it separated from the rest of the project. I’ve tried to copy and paste it into the For Each loop and it just creates duplicate sequences which messes things up.

Thanks for your help.

@Raghavendraprasad - Hello again, can you take a look at the attachment? I had a Copy file (it’s still there but I’ve disconnected it) activity that was saving each iteration as PDF but the files were corrupted. Now I have the Send Hotkey F12 and the Type Into but now it’s not saving as PDF and it is just saving the original template over and over without changing the name or file type. What am I doing wrong?Main.xaml (23.4 KB)
Thank you again

Okay will take a look at it and get back :slight_smile:

Hi there @mworth123

Seems like send hotkey is being sent generically not to a specific window. You need to indicate the excel window where you want to send the hotkey.

Secondly you can use select item from the drop-down for PDF attachment also and need to append .PDF at the end of the filename as it will be saved by the drop-down option that you selected.

Hoe this helps , get back if issues still persist.

HI @mworth123

To save the excel file as pdf. here you have an activity with less code.

Regards
Balamurugan.S

1 Like

@balupad14 - is this a third party piece of software? It’s not in manage packages in UIPath. Also, how do I open it?

@Raghavendraprasad - Thank you for your help.

  1. How do I indicate the window where I want to send the hotkey?
  2. How do I do what you’ve said above in number 2?

Thanks again

@Raghavendraprasad - Hello again, I’ve made some changes to the send hot key and the type into and re-attached the project. What am I doing wrong?
Main.xaml (23.8 KB)
Thank you

Can anyone answer my question? This shouldn’t be this difficult