VBA To Print Worksheet Array?
Jul 14, 2014Subscript 9 error that Ive been getting when I run this macro. It has worked in the past, but when I tried to test it today I keep getting errors on the array portion.
[Code] .....
Subscript 9 error that Ive been getting when I run this macro. It has worked in the past, but when I tried to test it today I keep getting errors on the array portion.
[Code] .....
Since upgrading to Windows 2007 (I was already using Excel 2007) I am having issues with the content in the cells on the worksheet not appearing the same on Print Preview and when I print. On the worksheet the cell show to be at the best fit both horizontally and vertically. When I look at the contents under print preview, the contents are squashed from the top and cut off from the left. This happens whether I have the format in Top or Central align and is even worse if I use Bottom align. It is also somewhat worse if I have thickened boarders.
I am using TrueType Fonts.
I just converted from Excel 2003 to 2007 and print previewed a worksheet and find a tiny image with a small portion of the print area. When I look at the sheet in page break preview mode, I see the 8.5 x 11 sheet broken up into approx 77 smaller sheets. When I try to move the page breaks to include the whole sheet it states the change cannot be made as it will result in an image less than 10%. I have attached two images - the first shows the print preview I get, and the second show the multiple pages when I view in page break.
View 4 Replies View RelatedI have an array and I want to graph it. I don't know how to do that so I am trying to print it to a sheet and graph the data that way.
This is my array:
blkhist(service, 1) = DateDiff("d", blkstart, rawdata(currentdate, 1)) 'x axis values
blkhist(service, 2) = rawdata(currentdate, 16) ' y axis values
blkhist(service, 3) = blkcart 'series #
I know I can print sheets as such:
Sheets(Array(2,4,5,8,9)).printout
I want to populate an array list based on sheet names, but cannot figure out the last line for syntax:
Dim ws As Worksheet, arr() As String
ReDim arr(0 To Sheets.Count-1)
For Each ws In Worksheets
If InStr(1, ws.Name, "Crp-") Or InStr(1, ws.Name, "Reg-") Or InStr(1, ws.Name, "Grp-") Then
arr(counter) = ws.Index
counter = counter + 1
End If
Next ws
Sheets(arr()).printout
As I debug it the array is filled with the proper sheets, but I for some reason cannot figure out the syntax for this line? Does it have anything to do with me declaring the array as a string and using integers as the index?
I have 9 named ranges on worksheet Sheet1. I want to print every combination of every non-singular range on worksheet Sheet2. Below is a simplified version of the scenario.
There are three named ranges: Letters, Colors, Animals. Say the below are the entries for each range.
Letters = {A, B, C}
Colors = {Red, Blue}
Animals = {Dog}I want to print every combination of Letters and Colors but exclude Animals since it only has 1 entry.
Therefore my result would look something like this:
A Red
B Red
C Red
A Blue
B Blue
C Blue
My thought is to make a multidimensional array GrandArray where GrandArray(1) = Letters and GrandArray(2) = Colors, then recursively go back through every combination and print to Sheet 2. I can set up GrandArray, but stepping through each element is creating mismatch errors.
I'm trying to avoid For loops since my real data has 9 ranges which may or may not be included in the final print.
I have created a macro that loops through and creates an array of the visible sheets. Now I would like for it to print each of those sheets out. I think my main mistake is in my declaration of the array type, since I have not worked with arrays much before.
how to make the following code operable. Currently when I run it I'm getting a "Run-time error (9): Subscript out of range" error.
The code prints a series of sheets. Afterwards these sheets are "group"ed together. The code can be accessed from 2 different sheets. I need to figure out how to get rid of the grouping and return to the original sheet.
Private Sub CommandButton1_Click()
Sheets( Array("Pipe", "Pipe Flow")).PrintOut
UserForm1.Hide
End Sub
I have a workbook that I am sending out to others for them to fill out. I would like to have them be able to click on a cell (or text within a cell) and have Excel print that worksheet in landscape mode or at least open the print dialog box.
View 9 Replies View Relatedwhat is the vba to print every worksheet within an excel workbook?
also, i've been working on saving each worksheet and have the code for that, therefore, can show me how to loop through the count of worksheets (which will be changing every time i run the macro).
is it somelike like count the worksheet(s) first and then loop all of them. from there within the loop i can call the sub SAVE() and use the cmd "ActiveSheet.PrintOut".
i am trying to use "Worksheets.Move After:=Sheets(Sheets.Count)"
but i am not getting there.
I finally found a vba that will print my excel worksheet as a pdf.
Sub PrinttoPDF()
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True
End Sub
My questions are:
-How do I set a path for this printout. right now its printing out the pdf on my desktop.
-How can I name the pdf file to a value in a cell. right now i have to manually name.
-Is there a way to email this file from the path i just saved it in?
I've set up a BeforePrint procedure as follows:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.ScreenUpdating = False
Dim ws As Excel.Worksheet
Set ws = ThisWorkbook.Worksheets("Objectives")
Dim i As Integer
With ws
For i = 9 To 33
If .Cells(i, 16) 1 Then GoTo NOTONE
If .Cells(i, 4).Value = "" Then
.Rows(i).EntireRow.Hidden = True
Else
.Cells(i, 4).Interior.ColorIndex = 2
End If
NOTONE:
Next i
End With
Application.ScreenUpdating = True
End Sub
... which works brilliantly....
My problem is that I don't know how to reset the sheet after the print!
Can anyone shed any light for me, please?
I have a workbook with 150-some-odd sheets, each with a store number. I would like to loop through each sheet & print that sheet to the printer with the same name in my printers & faxes queue.
(eg. sheet 9604 would print to printer name oki9604)
At my company we need to print our workbooks containing 3 to 24 worksheets. The first page should be printed on different paper than the other pages. From various forums I gathered that it's not possible to set the papertray using vba. Those forums suggest 3 things: 1. Windows Api functions (don't work at our company(security)), 2. SendKeys (don't work because of different printers, office versions and future-proofness) and 3.
Define printerdrivers per tray.
This last I did, so there are printerdrivers for tray3 and tray4.
With the following code I try to print the workbook:
Public Sub printSheets(strP1 As String, strP2 As String)
Dim curPrinter As String, firstPage As Worksheet, otherSheet As Worksheet, x As Integer
Set firstPage = Application. ActiveWorkbook.Sheets(1)
curPrinter = Application.ActivePrinter
Application.ActivePrinter = strP1
firstPage.PrintOut
The problem: The sheets are sent to the printers specified as strP1 and strP2, but the tray-settings from these printers are "overruled" by Excel; they are printed from the papertray that was the default of the printer when Excel was started.
Also, using the default printer dialog from Excel has the same problem; when the (windows-)default printer is Tray3 then all the pages come from there, even when printer Tray4 is selected as the printer. In Word or Acrobat etc the prints come from the right tray.
I have a worksheet set up with a number of pivot tables to show job summaries for each project manager. I created buttons labeled with each project manager that trigger a macro to filter the results to only show jobs for that specific project manager. There's one button for each project manager.
I'd like to create a macro that will essentially show each project manager's report and compile the result into one PDF. I only have 5 project managers so I don't need an array or anything if that makes it easier, I could write the code manually for each one.
So basically, it would do this:
1. Run macro to filter results to only show Project Manager #1 jobs.
2. "temporarily" print to PDF.
3. Run macro to filter results to only show Project Manager #2 jobs.
4. "temporarily" print to PDF.
5. Run Macro for Project Manager #3, etc.....
...............
Final step. Compile all the "temporary" pdfs into one file.
I am trying to copy the print settings(including the headers and footers) for one excel worksheet to another. I have found the following hint on internet and it works fine for copying the print setting(including the head/foot) but it is also grouping the worksheets. Click on the tab of the worksheet you want to copy. Then hold down the Shift or Ctrl key and click on the tab of the worksheet where you want the settings and click on File, Page Setup and OK. How can I just copy the print setting without grouping the worksheets?
View 4 Replies View RelatedI would like to set the printer area of an Excel worksheet. I would like to print one page starting from row A3005-V3220. However, I cannot change the print area. Excel wants each row to be another page. When I drag the blue print area lines, nothing happens. So right now I have 216 pages and only want one!
View 3 Replies View RelatedIn Column C (C11:C28) I have Sheet Names - Descriptors and then in Column D (D11:D28) I have the "YES" or "NO" for whether the sheet should print There could be blanks rows or rows with just heading text on them.
This project uses Table of Contents and what is on the specific sheet I use a Formula [=CONCATENATE("Agenda1 - ",Agenda1!H1)] on some of the Rows. These all then Hyperlink to the appropriate worksheet. Not all Rows will have the Formula if it is easily identifiable.
The name of the sheet is Either the Name As Is Unless there is a hyphen and if there is a hyphen then the sheet name is the first word up to the space.
I'm sure this is doable with VBA I just don't know how to manipulate the - out of the names and do the appropriate sheet selections so that I can print all of the selected sheets.
My current data looks something like this:
Info Pages Print (Merged Cell Header Row)
Title YES
Implementation NO
<blank row>
Agendas Print (Another Merged Cell Header Row)
Agenda1 - FORMULA NAME1 YES
Agenda2 - FORMULA NAME2 NO
Agenda3 - FORMULA NAME3 NO
... thru Agenda7
Other Print (Merged Cell Header Row)
Other1 - Formula Name NO
Other2 - NO
Other3 - NO
My workbook has worksheets with names: Title, Implementation, Agenda1, Agenda2, Agenda3,...Other1, Other2, Other3
I want to select all of them that have the YES to Print and then send them to my printer.
I tried recording a macro but I am keep on getting an error. I need a macro which will print the selection of A1:D28 on a worksheet called Invoice. The print needs to be scaled at 165% of its normal size. i need it to be normal margins and if possible any printer.
View 1 Replies View RelatedI am trying to create a simple macro to print a worksheet with a button. The worksheet will have additions/deletions on a daily basis, so it need to adjust accordingly. I cannot figure out how to do the loop macro.
View 9 Replies View RelatedI have a some code that we use in our office that works ok on my pc. When others in the office try to use the macro the year gets changed to 19 instead of 09. The only problem I have is that the code seems to slow down when it is trying to print the worksheet out. Can the code be shortened up/cleaned up. We are looking for gridlines with inside /outside lines, landscape and left/right margins of .25
Sub IC_Delays()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Add
Windows("Delays List.xls").Activate
Range("F15:N" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Windows("Book4").Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("A1:I" & Cells(Rows.Count, "A").End(xlUp).Row).Select.........
I made a macro to print the Invoice worksheet and I added a button to run the macro but I don't think I did it correctly.
Sub Print_Invoice()
Range("A1:G35").Select
Selection.PrintOut Copies:=1, Collate:=True
End Sub
This is the information I used for the command button:
Private Sub CommandButton1_Click()
Range("A2:G34").Select
Selection.PrintOut Copies:=1, Collate:=True
End Sub
I have a worksheet called "ComplaintData".
In this worksheet I have data in following range : "N1:V2".
N1 to V1 is headings and N2 to V2 is data transfered from listbox on userform.
I am trying to print this range via command button on my userform.
I am wondering anyone can help me with the code for selecting and printing this range when user clicks on the "Print" command button on my userform?
how I can format this print out to look different than the tabular format? I mean if possible I would like to print this in portrait, fit to one page and possibly not look like a table. (If it has to look like a table then I will have to go with landscape as the table wont fit portrait without getting too small and un-readable)
How do I change the print settings of individual pages within a worksheet. Specifically, I'd like my worksheet to print out 4 pages, the first as portrait and the remaining as landscape.
View 2 Replies View RelatedI want to print a worksheet where their are blank rows for future use between the main body of the data and the total row. I want to exclude the blank rows.
View 11 Replies View RelatedI have been trying to write a couple of macros;
1) save file as pdf, to be saved as filename=(cell in A1 & todays date (format yyyy-mm-dd)) and overwrite any existing file of the same name.
2) Email the pdf to a set of recipients round in Range "A2:A3", and subject = (cell in A1 & todays date (format yyyy-mm-dd))
I have a workbook with 100 tabs and I have an index page with checkboxes for each tab. I need a macro that will clear all of the checkboxes on the page with one button and a separate macro that will print only the checked tabs.
Can anyone write that code for me so I can just add it into my index tab?
I am creating a main worksheet (Legend) in which information will be entered and then populate to other areas (worksheets) within the workbook. I would like to create a print macro - that will run and print all the worksheets that we have selected on the "legend" page. These worksheets would have been selected by ticking a check box.
My question is how to associate a check box to a worksheet? For example - the second worksheet is named " Schedule A" 3rd "Schedule B" and so on.
- The check boxes will be name schedule A, Schedule B and so on.
- I would like to associate (link) the checkbox Schedule A with the Worksheet of the same name. Then when this checkbox is selected, and the print macro runs it will print the worksheets that are selected.
I have used Option Buttons and Combo Boxes on my worksheet. When I print my worksheet, the controls which contain values do not print properly. They only print a fraction of their actual size relative to the rest of the worksheet. The properties are set so that they are printable. What setting do I need to change for them to print properly.
View 2 Replies View RelatedI have data that is automatically entered in sequential rows down a sheet.
I have set up another sheet to format the data in a fixed print range to print Results labels with a Custom Menu PrintButton2_ClicK() Procedure. After a label is printed I want to change the color of the first cell in the row that just printed and then increment the counter so the next row of data is displayed in the print area.
I spent(wasted) a lot of time trying to get VB to accept an indirect address so I could change the cell color.
The code below works but I think there must be a better way.
Private Sub PrintButton2_Click()
'Use for Menu Item to Print Results Labels as they come in.
'Create sRow as String for Row Number to allow cell Color Change
Dim sRow As String
Dim nPCount As Integer
'Print Current Record (Label Print area on sheet "AutoPrint")
Worksheets("AutoPrint").PrintOut Copies:=1, Collate:=True