I am printing a sheet from a excel file as a pdf. This sheet is having multiple views/area. I have to print only few views which contains data and do not want to print the views which are blank. I already set print area for all the views. Blank views will have data in future hence I am not allow to remove them.
In current scenario, I am getting blank space for the empty views when I print, which I need to avoid. I tried various VBA macros but didn't have any luck yet.
Related
I would like to know if I can "manually" (through VBA) reorganize the order in which printing areas are printed.
Let's say I have an Excel document with 4 sheets, Sheet1 to Sheet4.
In Sheet2 and Sheet3, depending on situations, I may have 1 or several printing areas (i.e. several pages to print), 1 printing area = 1 full page. Other sheets are "regular" (single printing area, single sheet of paper printed)
IF I have only one page in each case, it's piece of cake... I print SheetX to page X.
BUT users can click a button to create one (or several) new page (s) in Sheet2 and/or Sheet3. I do NOT want to let them create new sheets as they will mess up all. Depending on previous choices, some sheets are displayed or hidden; in this case of several pages in the same sheet, printing areas are defined in VBA today.
IF I have several pages/areas defined in sheet2 and Sheet3, I would like to print them in this order:
Sheet1, Sheet2-area1, Sheet3-area1, Sheet2-area2, Sheet3-area2, Sheet4.
In any case, the printing of the document goes through a VBA macro and a user defined button.
My other solution would be to change page numbers with VBA and print all sheets in order, then users will have to reorder pages manually. Not a big deal with 10-20 pages documents, but still a source of mistakes and complaints.
I think I am more in need of a general idea of how to do it than code snippets. I cannot see where this can be done. I know how to use
ActiveWorkbook.SheetX.PageSetup.printArea = "B2:J34","L2:,S34"
I would need something like
ActiveWorkbook.PageSetup.printArea = Sheet1!"A1:H20", Sheet2!"B2:J34", Sheet3!"B2:L50", Sheet2!"L2:S34", Sheet3!"N2:V50", Sheet4!"A2:K22"
Any clue?
Just an idea but what if you use a macro to assemble all the print areas into a new workbook as individual sheets. Put the sheets in the order you want them printed and then print that workbook and close it. It's probably a little more overhead with all the range copying but could give you more control.
This is similar to another post I saw but different enough that I feel I needed to ask the question. I have a sheet ranges that I want to Export to a PDF. But here is where it gets difficult. One sheet that I need to print does not fit on the entire print area so what I need to do is print part of the sheet (Range) on one page and have the leftover columns print to a different page. Normally this would just need to be a separate range but I need to keep the leftmost columns for context of that second range. So the second page needs to have two print ranges on one page, is that possible? Or, can I somehow print the second page with a hidden area, i.e. removing the columns that were printed on the first page? If I went with this latter solution I would need to unhide those columns after the print job finished. I want to keep all of the printing exported to one PDF.
I did finally figure this out with what I think is the simplest solution. I copied the page twice onto separate worksheets and then simply hid the areas that did not need to be printed. I then delete the worksheets which always ask the user for permission, not the best but it works. As an enhancement I could safe to a separate workbook in the %temp% directory. That way it would not ask permission to delete as no deletion would be necessary.
ADD. I did not realize this but I can easily turn off the alerts in VBA and solve that display pop up problem.
I've seen some stuff online about exporting data, but what I'm doing is a Copy/Paste. I'm looking at a Datasheet View of an Access form, and I'm trying to copy it to Excel. The form has 2 Memo fields.
If I copy the Memo fields one at a time, I get all the contents of the field. If I try to copy the whole Datasheet View and paste it into Excel, the Memo fields get truncated.
Is there a way around this, other than exporting the data?
No, you need to export.
Note that the error is in Excel, not in Access - if you paste to a text editor, or view the copied data in Clipboard Viewer, you see that the clipboard data is complete.
But when you paste multiple cells to Excel, it truncates each cell at 255 characters.
If you Paste Special into Excel your text from Access will not be truncated. But check to make sure funny things didn't happen in other columns of your Excel worksheet. And you will end up with with a top line header you'll probably want to delete. Small price to pay for getting all the text over.
I have an Excel spreadsheet that generates CSV scripts used in an application. The scripts must be in a very specific format, and I save a master in XLSX format with protected sheets and data validation to save the CSVs from rather than directly edit the CSVs, as directly editing the CSVs can lead to mistakes.
The issue is that the scripts can be of nearly any length. The left column of each line can only be one of a certain set of values, and the last line has to say "END". The only way I can do this without VBA is the following formula in the A column, from row 7 (the first 6 are header information) to row 1048576 (last Excel row) and protect the sheet with column A locked:
=IF(AND(ISBLANK(B368),NOT(ISBLANK(B367))),"END",IF(ISBLANK(B368),"",A367))
This makes the last row say "END" in column A, and all rows after blank, which is what is desired. The problem is that now when the CSV file is saved, it will always have 1048576 rows, with all the bottom rows containing the delimiters ",,,," . This won't work, the CSV file needs to stop after the "END" row. Is there a way to write the formula that will cause Excel to ignore the cells which evaluate to blank when saving to CSV or an alternate way to save to CSV in Excel that will ignore all the rows that evaluate to blank?
Note: I have a solution in VBA already that I can use on my own machine (it copies the data up to "END", pastes in a new sheet in text only format, then saves as CSV with the name of the original worksheet). I want to share this sheet, however, and getting around the security constraints to share macros at my company is a pain. So I'm looking for a way this might be done without Macros, if it's possible at all.
In looking for an answer I found this link, which is similar, but not the same:
Saving Excel data as csv with VBA - removing blank rows at end of file to save
As the "blanks" I have are active rows because they contain formulas, this method will not work.
Manually deleting the rows / columns will work to reset the size, as GSerg noted in the other question. Alternatively, also as suggested by GSserg, you can copy the data to a new sheet before saving.
Otherwise, an easy fix might be to create a small post-excel / pre-processing script - perhaps using a batch file - Batch / Find And Edit Lines in TXT file - or a similar solution in any small scripting language to remove the extra rows.
I have a spreadsheet where I can enter a reference number and Excel generates a table based on the data tied to that reference number.
Rather than enter each reference number individually and copy the resulting table manually, is it possible to automatically iterate the process of entering the reference numbers (from an existing list) and exporting the results separately?
My Idea:
I didn't quite understand HOW you need to automatically enter those reference, but a good idea would be writing all the numbers you need in a .txt file, then program a button which loads a msoFileDialogFilePicker to select your file. When the file is selected, you can open it with a New FileSystemObject, read it with ReadLine and filling an array with all the numbers you have written in the .txt file. Then with a forcycle from LBoundto UBoundof that array you can enter those numbers automatically in your Range.
To export everytime your results table (which again I didn't quite understand HOW you want it to be exported), an idea would be a Worksheet Changeevent (if the results table appear in your spreadsheet) in which you can write down some code to copy-paste the results table in a new worksheet and then save it, or make a .pdf of the results table from its area.
The possibilities are really too many to write a single piece of code to show you :)