I am trying to determine the visible worksheet area in points. So far, I have tried the Application.Width, but that gives me the entire area including the scroll bars, and likewise Application.Height includes the ribbon and horizontal scroll bar. What I need specifically is the size of only this viewable worksheet area.
Something I have tried so far is looking at the visible range. For example, if I can see A1 thru AA40, then I can use the code
Debug.Print ws.Range("A1:AA40").Width
Debug.Print ws.Range("A1:AA40").Height
The only problem with this is if I can see half of column AB and half of row 41, then I don't have the full size. Also, it is not adjustable if I decide to change the application window size to half the screen.
I have no need for converting into the number of pixels, I just need the point sizes. Does anyone know a way to get the visible area size, or at the very least how to resize a range to fit only this visible area?
You can access the Windows collection of Application and use the Width and Height properties of items of that collection. E.g.
Debug.Print Application.Windows(1).Width
Debug.Print Application.Windows(1).Height
You can also refer to ActiveWindow and get the properties from that as well.
Example:
Grid's dimensions:
?Activewindow.activepane.VisibleRange.Height, Activewindow.activepane.VisibleRange.Width
The above worked for me, returning the dimensions of only Excel's grid which could be seen on my screen- no scrollbars, no Ribbon, no formula bar - just cells displayed.
Related
I have a time based chart and I am trying to print it on one pdf page. The chart spreads from column 'B' to 'UR' ~ 560 columns. I have the print setup for that area and to fit one page. It prints till column JU and disregards the rest. Not sure if there is a work around or if I am missing something. And if there is a vba script that can help with it.
I tried some additional variations and did experience the cut off issue. I couldn't quickly work out what created the limit, but it wasn't the number of columns; a guess is there is a limit to the size of the hidden "canvas" on which the chart is painted before its scaled back to print and/or save as PDF ... hence is related to the width of the chart. However you can see (roughly) from the screen shots below a chart spanning from B to UR (limited by yellow in column UR); the chart is 319cm wide. Then the saved PDF. The page setup was A4 landscape with narrow margins. Cheers.
I'm looking to set up a scroll bar in Excel that corresponds to what set of data I use for a chart. I have built a 2-value doughnut chart that acts as a percentage gauge (green section is completed and grey is 100% minus the completed part).
I want to be able to choose what month's data I use for this chart using the scroll bar. All I can seem to find online is how to modify the number of rows and columns that are displayed on a graph rather than actually using the scroller to pick what data to display.
In addition, how would I make it default to the current month? Any help would be appreciated!
For anyone that is looking for a similar solution, I have figured it out. It works with something called a dynamic range. Use the value of the scrollbar to determine the offset of rows (pick which row of data to use). Then link that dynamic range to your chart in place of where you would select the data.
I've created a macro that I assigned to a shape, which allows me to click on the shape to hide or show a picture. This works great !
What I want to do now is link this shape to a row of a spreadsheet, in a way that when I sort my spreadsheet, my shape follows the same row. It currently stays on the same cell when I sort (I do select all of the cells when I sort)
What I've tried so far :
-I have right clicked and set the properties of the shape to "move and size with cells". This does not prevent the problem.
-Typing "=the_name_of_the_cell" into the cell containing the shape, but it doesnt work.
Thanks in advance !
edit : rephrased it
You can use the shape's .Left and .Top properties to move it to a fixed range on your worksheet. To keep it in a certain row you need only the .Top property.
The following example assumes you want to keep a shape called "Example" on row 7:
ActiveWorksheet.Shapes("Example").Top = ActiveWorksheet.Range("7:7").Top
The shape's property of Move and size with cells will work, but the shape has to precisely fit inside a single-cell for this to work when sorting.
Click the shape, hold the Alt key and resize each of the corners. It should snap into each of the cell's corners (with a little care). Increase the Zoom if it helps.
Hide some text in the cell behind your shape and it should follow with your sort. That worked for me. I also have the shape properties set to "Move and Size With Cells". For example, I have a DELETE button on my row. The button text says "DELETE". The button shape is small and fits in one cell, and so behind it, I typed the word DELETE. The button shape covers it so no one can see it and I also made the font color WHITE so it will not show when printed.
I have placed two crosstabs one below another. But They are not getting aligned. How to align the two cross tabs such that corresponding columns align perfectly.
The quick and dirty way is to use fixed widths on all cells.
This will work fine for PDF, but will not work for HTML if:
You're using a modern browser (IE9+, FF/Chrome from last 5 years)
The total width exceeds screen size
There is no total width set on the crosstab itself
It will then ignore the cell widths and try to force everything to the screen width, thus the crosstabs will not align again.
I wrote some JavaScript awhile back which will combine two tables into one so fixed width is not needed. The full blog post is here. This will only affect HTML outputs, so for PDF I created a second page and just conditionally rendered one depending on user selection.
Fixed width is the only viable solution )
But you can use Report Classes to have a single “width” definition and apply it everywhere. It actually makes your reports look way neater.
Use Blocks in the cross tab cells, you will need to unlock the report first to do this
Set the block size to be the same on both cross tabs and then select content is clipped (Size and overflow property of the block)
This will work for both html and pdf output
I was able to do this by doing the following:
Set the Size & Overflow > Width of BOTH crosstabs to the same width in pixels.
Unlock the report, select the crosstab Text items in BOTH crosstabs and set them all to the same width (or individual columns to the same width if needed).
With the report still unlocked, select the text items in the crosstab 'Rows' and set those to the same width.
It's not pretty, but nothing in Cognos ever is.
I have some trouble with a document when exporting it to pdf with the builtin pdf export function of excel (2010).
I've generated a graph on my worksheet, with some colored cells arround it. Visually it looks good (even if I zoom on it with the ctrl key + mouse wheel). But when exporting, the graph overlap the surrounding cells.
For example, on the image bellow, I take a screenshot of my graph in excel (at top) and in pdf (at bottom). The red part is my graph (I've colored the background of the graph object). The graph have a black border. And just on the top of the graph, I've colored the background of a cell in blue. Normally, the graph must not overlap the blue cell, because I've manually place it bellow (cut the graph, select the cell bellow the blue one, and past the graph to this emplacement).
But we can see that:
the black border overlap the blue cell (in excel and in pdf version; but it's not really my problem; I've understand that the border in excel object is at outside the object; and then overlapp surround objects/cells).
the graph (in red + the border) has not the same place in excel and in pdf, there is a big offset (it's not a resize problem, this offset is present and the left side too). The place of the graph is more on the left and more on the top in pdf version than it can be!
(I'm using this to automatically generate reports; and the result is not visually good)
Is there any way to overcome this problem?
Hmm, I can't replicate your problem, but I've had similar issues exporting Crystal Reports to PDF. Here's 2 suggestions, neither of which is perfect and I couldn't try them first (again, sorry I couldn't replicate the problem):
Add a white row with a very small height between the graph and the cell. It might even be visually more appealing than the 2 objects one on top of the other.
Make your graph's background transparent and hide the border. Maybe add some extra white space at the top of your graph. That way, they'll still overlap, but it won't be as obvious.