I have 1 routine that is structured like this:
C#console C opensxlworkbook A- C then runs A’s macro M which saves the target worksheet as a PDF using VBA
- C then uses
PDFsharpto encrypt the PDF file. - C then emails this file.
Currently this procedure is for one report so no problem if the architecture isn’t textbook.
I imagine in the future there may be many target worksheets in many different workbooks all going to lots of different recipients. If this is the case then Step 2 will need to go as I will not want to have to copy this VBA code into every target workbook! The only alternative I can imagine as my experience is limited is the following:
- Take the current VBA code out of Excel and move it into C using a reference to
Excel.Interops
Assuming that the target worksheets are the finished article i.e. no further manipulation is required before going to PDF is the above the correct approach for moving this step out of VBA and into the console, or should I create the PDF using a different library?
The least-effort option is moving the code from the worksheet into a VBA add-in by deleting all the sheets/data out and then use ‘save as’ to turn the workbook into an add-in which you can then load into excel and will be available all the time. Depending on how you’ve written it some changes may be required but they won’t be as big as a port to c#.
That said, having the code all in one place will make the whole process easier to look after in the future. Plus you’ve already got C# code automating excel to fire the VBA so it may be better to do it now if you have time.