Forum Discussion
VBA Programming Assistance
Hello Deborah,
I took some liberties, and made some small modifications. First, I saved it as .xlsm, as it is the current file format for Excel, and the older format was trying to revert some things. Second, I deleted all except one line of your Invoice Register table. The VBA code checks to see if the first cell of the last row is blank. If it is not, then it adds a new row to the bottom, and then populates the Job Number, Order Date, and Vendor Name of the last row from your PO number. It exports the active worksheet (it will probably always be the Purchase Order Form, since that is where the button is located, but if you were to initiate the macro from a different tab, it will export that tab). It saves it without prompting, and if the same filename already exists, it will overwrite it without warning. It then opens an email with the subject "Purchase Order " and the PO number from the form, and attaches the pdf file to the email. That last bit was an assumption on my part, and if you don't want it to attach the file, you can delete the .Attachments.Add attpath line near the bottom of the code. I hope it works for you.
- Deborah ThornburgSep 20, 2018Copper Contributor
That is so amazing and I promise I will read through the code and try to understand it all so I don't have to ask so many questions in the future! The only thing is when I click the "Save File" button I get the following error:
As it relates to the .Attachments.Add attpath line in the code.
I do want the file to attach to the email so you assumed correctly and it really is very much appreciated!
- BobOrrellSep 20, 2018Iron Contributor
Another thing that I noticed that you may or may not want to change. The Submit image (button), and SAVE FILE button both are visible on the exported PDF. If you want them to not display, you can set them so they don't print. They are different types, so the steps for each one is different. Let me know if you would like some assistance with that.
- Deborah ThornburgSep 20, 2018Copper Contributor
The button being on the form isn't that big of a deal to me but interesting to know you can remove it. Now when I try to save it it pops up with a printer dialog box:
And when I hit "Adobe PDF" I get this:
And then this:
As it pertains to this:
Now clearly I am no expert, barely even a novice, but why it is telling it to print? I didn't see any code that looked like a print command. Is that just the default for pdf?
- BobOrrellSep 20, 2018Iron Contributor
Sorry about that. When I was testing it, I was saving the pdf to the same drive that the workbook was saved to. I forgot to tell it to look at a different drive. There was also an extra \ in there too. I've made the corrections, and this should work for you.