How do I replicate and center an object in an Excel worksheet using VBA? - vba

I have some VBA that takes the contents of a few different worksheets, and prints them to PDF. I'm trying to add a watermark type effect to each page that gets printed. However, not every page will receive the same watermark. I have a textbox that will correctly get updated as the VBA is running, and will always have what I want my "watermark" to be. I've gotten to the point where I can copy the textbox and paste it in a specific location, but I need to be able to paste it in multiple locations, which will not always be the same. I'm looking for each page to contain the "watermark" and for it to be centered (and potentially resized down to the dimensions of the page in a case where the watermark is larger than the page). Additionally, the number of pages added to the PDF by the sheet is variable, but all pages should always receive the "watermark". I have virtually no background in VBA. The below code was produced by recording a macro.
Sheets("Sheet 1").Select
ActiveSheet.Shapes.Range(Array("TextBox 3")).Select
Selection.Copy
Sheets("Sheet 2").Select
Range("C16").SelectActiveSheet.Paste
I need the paste location to be dynamic and centered in the middle of the printed page. I also need the image to appear on each printed page.
Any help would be greatly appreciated.
Edit: One of the things the existing VBA does is print all the pages on the worksheet to PDF. It then changes values of the pages, and prints them to PDF as well. I need the watermark to update when the values do, which is currently working. The problem I am having is that when the values change, the number of rows change, and so does the page count. If I had a static page count I would just add the watermark (which is already updating as needed) everywhere it's supposed to be.

Related

ckeditor5 Paste with formatting but without images

I like to paste but have an option to retain all formatting but have all images stripped. This is particularly useful when users are pasting content from emails to record against a trouble ticket but don't want the image content to be included namely as most of the time the images are in the signature of the emails and in long threads these images don't paste well
I know we can do a ctrl-shift-v paste which does plain text but it loses all the formatting which is a plain than for a user to go through a big paste and format the message
I like this feature either with a new button or a popup asking user if they like to strip out images when an image is detected in a paste

Is there a way to find the page break locations in an xlsxwriter worksheet?

In my code I generate a worksheet that uses fields with text wrapping, so I don't know exactly how many lines will be on a page when xlsxwriter creates the worksheet. Due to limitations in the app into which I need to import the xlsx worksheet, I need to take my original worksheet and split it so that each page becomes a worksheet in a new workbook.
Can I somehow access the location of page breaks after running fit_to_pages(), or alternately, is there a way to know exactly how many rows will be used when you run text wrapping on a field?
Can I somehow access the location of page breaks after running fit_to_pages()
No. That isn't stored in the file format. Excel calculates that at runtime when it loads the file.
Excel also adjusts the height of cells containing wrapped text automatically at runtime. You could prevent this by specifying an explicit row height for the rows that contains the wrapped text so that their height isn't adjusted automatically. However, setting the height explicitly for wrapped text requires some sort of estimation, which takes us to the second part of your question.
or alternately, is there a way to know exactly how many rows will be used when you run text wrapping on a field?
The only way to do this with 100% accuracy would be to use some Windows API functions with bounding box calculations. I'm not sure if that is (non-theoretically) possible in Python and if it is it probably isn't portable.
So you are going to have to make some sort of compromise and use explicit row heights that will allow you to calculate the height of the printed page and thus the page break location but not have the nice automatically height adjusted cells for wrapped text.

Locking text fields in embedded document

I have been tasked with updating a spreadsheet that produces a report by replacing text in a template. Previously, the worksheet referenced an outside/separate file-- my job is to get it working in an embedded document.
I currently have text form fields for every input I want to insert within the embedded document template. As it stands, users can edit the document template however they like, but if they accidentally erase a text form field (again, where text is replaced via the vba macro) then it will break the macro and the spreadsheet will be useless.
My question:
Is there some way to lock or protect text form fields such that the rest of the document is editable? I essentially want to have the inverse of a "text form field only" protection.
Alternatively, is there a better way to approach this project? I'm thinking of leaving the spreadsheet as is, but including a "reset" button bringing the template back to it's original state if anything breaks. If I did this method, this would require there NOT to be an external file. Attempts to do this so far have proven unsuccessful.
My general methodology/algorithm goes as follows:
Open the reference document
Replace all the text form fields via bookmarks with plain text,
making sure to reassign the bookmarks afterward (so as to not lose
them if they run the macro more than once).
Save the embedded document as a .doc with the inputs inserted
Replace all bookmarked inputs with text form fields to return the
template to its original state
Any information would be IMMENSELY appreciated. I am slowly running out of time and am feeling stuck.
Many thanks!
-Sooji

Print multiple pages per sheet with space between the pages

My goal is to print multiple pages/ slides of a pdf document (a handout of a power point presentation) on one sheet, so that one sheet contains two pages/slides.
Additionally there must be a space between the slides of one sheet.
The page should look like:
start of the sheet sheet,
page 1 (slide of the powerpoint),
space of about 5cm,
page 2 (slide of the powerpoint) ,
space of about 5cm,
end of the sheet sheet
A further option is that the space between the slides contains an scale paper layout.
Exist there any software which can do that?
Thank you for your help
The free and open source tool pdftools can achieve this.
You can put more slides in a single output pdf page using the --nup option, ad adjust the space between the slides using the --delta option.
There are several pretty print software utilities out there that have options on saving paper by combining multiple pages onto one sheet.
Your easiest solution however would be to use the operating systems print dialog, which generally has an option for printing multiple pages onto one. To create the space needed you can set scaling of the page to 90% or less if you feel you need a greater border. I just checked this on my MacBook and confirmed this.

vb.net code to enlarge font size, font name and do page setup in ms.excell

I am creating an excel report from vb.net. Now it works. But i realize that the apparent does not make sense. I just want enlarge some font size and change font name plus setting up the page to fit my receipt printer (Epson TM-T88IV).
what should i do ?
thanks in advance
First manually set everything up bit by bit until it all fits nicely on your receipt printer.
Once you have everything just the way you want:
Generate a new, plain copy of the report.
Start recording a macro
Manually replicate the changes that you did in your practice sheet onto your macro recording sheet.
Stop recording the Macro, and press Alt-F11 to get to the VB that was generated.
Use the relevant lines of the generated macro to see what you need to add to your report generation code.