Set Window Size With VBA.
I'm looking for a way to use VBA to set the window size upon opening the workbook. When the document opens, there should be two windows, each taking up half the screen and each on a particular tab.
Currently, if I save the workbook with the window settings I want, when I open it, both windows are maximized. When I hit the restore button, they go back the settings with which they were saved, which is what I want it to look like as soon as it's opened. Also, a bonus would be for the code to determine the screen size, so it can fill the screen no matter what monitor/computer it's opened on.
View Complete Thread with Replies
Related Forum Messages:
Set Window Size Based On Screen Resolution
I have an Excel based application that needs to run with a screen resolution of 1024*768 in order to display correctly. Is it possible to use VBA to detect the users screen resolution. Then: If the screen resolution is not set to 1024*768 then resize Excel's main window to run at that width and height?
How To Size App. Window To Fit Cells? (not Zoom)
This "smells" like a simple question, but I've had no luck finding a way to [programmatically] adjust the App.Window to fit around some cells.
I've found "Application.Goto", also the Application.Width/Height setting. The App.Width setting is pixel based, so if there's an easy way to know a cell's pixel-location, that'll work too!
Set Range Of Varying Size
I am try to Set a range to a variable. The problem is the range differs in size. The good thing is there is a blank cell before each group that I am attempting to set the range to. I know it should be possible to set the range to stop at the blank row. I am locating the correct row by the date and want to set the range to include the next three cells to the right and all the cells below them up to the blank row.
Set Font Size Depending On Length Of Text
When a number is entered in cell S3, it triggers formulas throughout the worksheet to populate the it with information from another sheet. If the length of the text in B6 is greater than 80, the font size for B6 only should be 8; if the length of the text in B6 is less than or equal to 80, the font size for B6 should be 10. Regardless of the length of the text in B6, the font size for the rest of the sheet should not be changed.
I tried the following
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address "$B$6" And Target.Count > 1 Then Exit Sub
Dim cnt As Long
cnt = Len(Cells(6, 2).Value)
If cnt > 80 Then Cells(6, 2).Font.Size = 8
ElseIf cnt < 80 Then
Cells(6, 2).Font.Size = 10
VBA Grab Active Window Index
Dim iStartBook As Long, iNewBook As Long
iStartBook = ActiveWindow.Index
iNewBook = ActiveWindow.Index
I'm trying to grab the "2" that .NewWindow generates. The above gives 1 both times, despite the obvious 2 in the caption after you run it. So what property works? What does .Index mean here?
Does A File With VBA Grow In Size
I created a new form for our field personnel to complete daily. They are telling me that over a few weeks the file grows in size. The file size is 335KB starting out end up in a few weeks being 3.5megs. Now they add on some other sheets and things which undoubatbly make the file size larger but I am wondering if there is anyway thet VBA could somehow make the file bigger as the open it each day over a few weeks? They are not adding in any VBA, they are only using the code which is provided, which is accounted for in the 335kb. It seems unlikely but i thought i would ask.
VBA To Split Size Of Cells
I have created a VBA which organizes data from duplicate accounts into a single row so that it is properly formatted for our email system. The one issue I am having trouble handling is cell overflow. Column B cannot end up with more than 5 pieces of information. Each piece of info is seperated by a comma. If there is overflow, the extra data needs to be moved to the following column.
With the example I have provided, you will see that after running the macro, cell B2 has 18 pieces of information. I need to expand the macro so B2 contains 5 pieces, C2 contains 5 pieces, D2 contains 5 pieces, etc.
Will VBA In Place Of A Function Reduce This Workbook Size
I know that VBA doesn't always slim down workbook size and calculations are calculations whether in VBA or Formula format; but in this instance, do you think VBA would be a better choice? This workbook is currently enormous in size and slow, and I think I can slim it down if I used the right VBA procedures. However, Im not certain what those procedures would be.
On two seperate worksheets in a workbook, I have a column that contains a formula that references a third sheet.
Sheet 1 = "Order"
Sheet 2 = "Turn-in"
Sheet 3 = "Bank"
Ok, here's the scenario: On the "Order" sheet, I have a list of orders from my company; on the "turn-In" sheet, a list of turn-ins. The "Bank" sheet lists ALL transactions (ORDER AND TURN-IN).
On both the turn-in and Order sheets, the formula is pretty much the same; it references a different column on the bank sheet, but does it the exact same way. Ok... The Order sheet lists all order from the company by order number (column A); the formula uses that order number and finds the transaction on the "Bank" sheet and returns the order cost as the result. however, the order numbers on the bank sheet have a 5 digit prefix on them (the prefix is the same on all orders, its used by the bank but only orders with my 5 digit prefix are on the list sent to me and pasted to this sheet. So all orders on bank sheet have the same prefix)
The below formula is in Cell C10 on "Order" Sheet; Column C lists the Cost reported by the bank. The formula below references the Bank sheet database, looks for an order number that matches the order number in A10 (Adding the prefix of course), and returns a cooresponding cost for that transaction.
I know this seems long for what it is, but it has to add the prefix, and then match the order number, and reference the cooresponding cost.
The kicker, this forumla is in more than 10,000 cells; 6,000 on the order sheet, and 5,000 on the turn-in sheet. Of course the references are a little different, but the principle is the same for all of them.
Is there a way to do this in VBA to save space and resources? This formula is really dragging.
VBA To SHADE Cells Based On: Step-size & Starting Cell
I have a spreadsheet that will monitor payment schedules, in which both payment frequency and the payment start date are inputted by the user.
As such, to make filling out the column(s) fool-proof, I want to grey out cells in which data should not be entered.
For example, if the payment frequency is every 6th day, and the payments are to begin on day 0, then days 0, 6, 12 (etc) should be left white, whereas the remainder of the cells should be shaded.
I can achieve this using multiple conditional formatting rules in excel2007 with iterations of formulae of the type:
Display All VBA Code In Code Window (VBE)
When I started using VBA, all the code for each module was shown in the code window. This was a bit cumbersome when looking for one sub in particular. Now when I load VBA, all the Subs and Functions have their own page, and can be selected from the right hand drop down list. This is much easier for entering code, and finding subs. However, it is sometimes useful to see 'the big picture', so how do I swap between the two types of display?
To Set Up A Condition Is Vba
Been teaching myself VBA and I've gotten stuck, and no matter how I search I can't seem to find an answer...
Trying to set up a condition is vba where if a cell value minus another cell value is greater than a static value (elsewhere in the sheet), then to turn the font green.
Code so far:
Dim Cval As Integer
Cval = Cells(3, 6).Value
FinalRow = Cells(65536, Cval).End(xlUp).Row
For i = 10 To FinalRow
If Cells(i, Cval) - Cells(i, Cval + 1) > R6C5 Then
.Font.ColorIndex = 10
.Font.Bold = True
I can't work out the right sintax to get a if condition to work correctly.
I have gotten this to work with conditional format, but if you want to copy/paste elsewhere, it doesn't paste the format result correctly...
Set Locations Using VBA
I have to manually cut/paste each excel doc which belongs to a specific Store folder, and copy then into their own shared directory, so for example:
Lets say my company has 10 Stores, and I know their online folder locations, the first step I guess would be for me to map the locations of each store, I am not sure what the best way to do this is, would I use the Case select ? to make the set = ?
So for example, Stores 1 - 10.
Set 1 = Dir("Z:Northwest1")
Set 2 = Dir("Z:Northwest2")
Set 3 = Dir("Z:Northwest3")
Set 4 = Dir("Z:Northwest4")
Set 5 = Dir("Z:Northwest5")
Set 6 = Dir("Z:Northwest6")
Set 7 = Dir("Z:Northwest7")
Set 8 = Dir("Z:Northwest8")
Set 9 = Dir("Z:Northwest9")
Set 10 = Dir("Z:Northwest10")
I am not an expert on Case Select, but was thinking:
Select Case myStores
Case Is = 1.......................
Set Protection Using VBA
I tried the following code and it doesn't work:
Selection.Locked = True
Selection.FormulaHidden = False
Range(Range("A" & Rows.Count).End(xlUp).Row & "A300").Select
Selection.Locked = False
Selection.FormulaHidden = False
Selection.Locked = False
Selection.FormulaHidden = False
I want to be able to unlock all cells after the last cell that has data in column A down to row 300. Also need to unlock cells AE11:AG300. What's wrong with my code?
VBA To Clean Data Set
A1Bad Data2Bad Data3Bad Data4Bad Data5Bad Data6Bad Data7Bad Data8Bad Data9Bad Data10Bad Data11Title12Good Data13Good Data14Good Data15Good Data16Good Data17Good Data18Good Data19Good Data20Good Data21Good Data22 23Bad Data24Bad Data25Bad Data26Bad Data27Bad Data28Bad Data29Bad Data30Bad Data31Bad Data32Bad Data33Bad Data34Bad Data35Bad Data
Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
How can I ensure that all Rows before "Title" and all Rows after the last populated Row (denoted by the fact that there is a single blank Cell after it) are completely deleted?
Using CodeName In VBA To Set New Formula
I am writing a VBA macro to update a financial workbook. 10 of the sheets within the file are re-names depending on the start of production date. So, in one file they may be CY09, CY10, CY11...and then in another CY10, CY11, CY12. I need to update the Cell L14 on the first CY page to a value on the BOM page.
I want CYXX!F12 = BOM!L14
And CYXX's code name is Sheet3411
To do this, I want to use the code name - because it is the same in all the files I have (100+).
But I cannot find enough/right Codename reference information to make this work.
Sheet3411.Range("F12").FormulaR1C1 = "=BOM!RC"
I would appreciate if someone could help with this particular issue. (A little explanation of when I can and cannot use the codename would be appreciated as well. As this is something I will be maintaining for years.)
Set VBA For Default Printer
I need an assistance in setting up a VBA for the default printer in my office. The issue is I want my spreadsheet to be set up to wherever I open the spreadsheet at any computers in the facility. I want the sheet to be printing out directly at the printer in my office only. Is there a way to do this?
Set Conditional Formatting Via VBA
I would like to add conditional formatting for the whole row based on whether the value of cells in column A is "CON".
For Each c In r
If c.Value = "CON" Then
c.EntireRow.FormatConditions.Add Type:=xlExpression, Formula1:=c.Address = "OK"
c.EntireRow.FormatConditions(1).Interior.ColorIndex = 35
the "CON" is a formula and can later take the value "OK".
The conditional formatting should highlight the whole row as green when that happens.
Set Range For This Vba Code
Selection.Replace What:="_", Replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
I want it to do this for range AL2 through AL2000. Ive tried a few codes trying to get it to work, but cant figure it out.
Vba To Set Print Area
Looking for a macro that will set the print area on an accounts spreadsheet to the last non blank row, bearing in mind that all the rows contain formulas, have tried some macros but they assume the cells with formulas in them are non blank
Set Tools/Options From VBA
I use several different workbooks during the day, and sometimes I would prefer the " move selection after enter direction" option to = "Right" and sometimes "Down". It doesn't seem to be an option that is saved with the workbook.
what could be done to a workbooks code to change this option upon opening the book?
Set Font Color In VBA Script
I have a script that sets font color. I think it uses something called "myColor" to define the color, and then pulls the color from a palette of 57 colors.
But how can use the "color" property instead, so I can have a broader range of colors? I can't tell how it would fit into my code. "MyColor" doesn't even show up in Excel's help file.
Here is the code. How can I adjust it so that I can use, like, "RGB 0, 0, 255" instead of color 32?
Or how would you code it so you could set color that way?
Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column < 8 Then Exit Sub
If Target.Column > 9 Then Exit Sub
Dim myColor As Variant
Select Case Target.Column...........
VBA Macro- Apply Set Of Commands
For each cell in Range(“B7:B50”)
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
Range("C” & cell.Row : ”T” & cell.Row").Select
Range("C" & Cell.Row).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
I am trying to apply this set of commands to each cell in the range B7:B50. For each of these cells, I need "cell.Value" to refer to the value in the respective cell and "cell.Row" to represent the row of the cell that is currently being used.
Way To Set The Printer's Properties Using VBA
Is there a way to set the printer's properties using VBA?
Sometimes we set the printer for BEST quality to do photos or brochures. Well if we don't change it back, when we go to print a spreadsheet, it takes forever because it is set on best quality.
I want to be able to set the print properties to normal using VBA.
Set Autorecover Save Location In VBA
I have a macro which performs the auto save function perfectly. I'm looking at possible enhancements.
1. How to set autorecover save location in VBA? I know how to do this on the front-end i.e goto tools/options/save tab and set it there As i have disabled save autorecovery feature, autorecover save location is greyed out
2. How to create a backup of my workbook? So that my workbook will perform autosave and when i close this workbook at the end of the day all the latest changes are added to the backup and saved
VBA Set ODBC Connection String For Query
My workbook has 9 queries, all needing the same string. I would like to have a msgbox pop up, let them enter the directory name, and have that change all the odbc conneciton strings automatically. Can anyone point me in the right direction?
The message box would be a nice touch, but is not necessary, I can change it in the VBA editor if needed.
Currently, they connect using a Visual FoxPro ODBC driver. We setup the connection when we made the queries. Now that they are in on the worksheets, I want to be able to edit them with VBA instead of using the script editor (which is very slow).
VBA To Set All Pivot Fields To Default Values
I am finishing up a macro that manipulates a pivot table and creates a file for us to run. But we all keep this pivot table up a lot, and usually keep a lot of the data filtererd in it.
Is there a way to set all of fields in a pivot table back to their default values like when you first open up the workbook?
Vba: Set Print Format Across Multiple Sheets
I'm trying to write a macro to select all the Sheets in a Workbook, and set some properties [Auto ColumnWidths, Landscape, and Fit to 1 page wide] for all of them.
I don't know the names of the sheets, nor how many there will be - this part is tagged on the end of a long macro that creates new files and pastes various data into them. The code below only seems to work on the Active sheet - not any of the others selected. Curiously, I can set a specific column width for all sheets, but not Auto Widths.
.PrintTitleRows = "$1:$1"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
ActiveWindow.Zoom = 80 ' This line works!
Selection.RowHeight = 13.5
Selection.ColumnWidth = 34 ' This line works
Set Up A Direct Link To The Internal Calculator, Using A Button In VBA
I'm trying to set up a direct link to the internal excel calculator, using a button in VBA. I have the shortcut on my own toolbar, but I have many users that use the workbook, and to get them all to set up is almost impossible, so I am trying to make it simple for them.
I've tried doing it through a hyperlink direct to the calc.exe file, but get a lot of messages popping up (that'll scare a few of them). So thought I would try and find the excel name for it and use VBA, but I cannot find it anywhere.
VBA - Adding Border Line To Bottom Row Of Set Print Area
I am using the following macro to set print area which I found on the net. I am trying to modify it as I would also like to place a border line on the bottom row but cant find anything to assist me despite searching through several threads.
Dim myrange As String
myrange = .Find(What:="*", After:=.Range("A1"), LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Address
ActiveSheet.PageSetup.PrintArea = "$K$1:" & myrange
VBA Code To Set Unknown Range Based On Current Date In 1 Column
i have a sheet for monitoring sickness. i have used a macro before which automatically selects a range and emails it to recipients when i press a button. what i would like to do is have excel automatically choose the range for me based on today's day. in the attached example i would like column "A" copied along with the 5 columns before today's date, today's date column and also the 5 columns after today's date. paste the lot into an email and send. (i have highlghted the parts i would like copied and pasted into an email based on today's date (21st july).
Copy, Paste, Change Font Size, Copy, Paste, Print VBA
I'm using 2003.
1. Copy cells B5 to V-First blank row in Strength Tests worksheet
2. Paste cells into Racks worksheet in cell C5
3. Change font size to 6
4. Sort by Column T descending then by Column C ascending
5. Copy one row (A5-W5 (1Rx23C)) from Racks worksheet
6. Paste row into M1 worksheet in cell D4
7. Print M1
8. Drop down one row on the Racks worksheet
9. Repeat steps 5-8 until there's a blank row.
Closing Immediate Window
Is there any way to have a macro, that is started from the immediate window, close the immediate window when it's done. My macro closes the immediate window, but as soon as it ends, the immediate window reopens and my cursor is inside it.
New Window On The Taskbar
i was recently upgraded to Excel 2003 and have found that whenever i open more than one workbook, it opens in a new window on the taskbar (similar to opening another application)... I remember having this in my previous version of excel but i can't for the life of me remember how i switched this off?
I open up Excel by double clicking on a file, it opens but it just has a grey background and the file I opened is displayed as a small 1 inch stip in the top left - just a title bar with the windows maximise, minimise and close buttons.
What ever I click I can't see any of the cells!
There is a column with a formula and a list validation, and an adjacent hidden column with numbered ids. When moving into the list validation cell the Worksheet_Selection_Change event code saves information about the Target cell - value, address, formula. When a value has been obtained from the list the Worksheet_Change event code looks up a belonging id in a lookup table and put this in the hidden id cell, and puts the saved formula back into the list validation cell. This makes the sheet (or window) unmanagable.
When I move around the sheet I can see the cell name in the Name Box, but the sheet itself is not visible. The only way to display the sheet is to add a new window (Window - New Window), choose the first "frozen" window (Window - 1. window) and quit this window. Then the new window is ready for use, but of course with the same limitations as the newly quitted one. Ring a bell, someone?? The funny thing is that in this workbook I also use the same functionality in another sheet without any problems.
I've built a macro to run a loop that opens excel files, prints certain sheets and closes them. I have the macro working - to some degree. here is my code (this is excel):
OldPath = "S:RMBS_Performance_Analytics Analysis1 Staging Folder For Monthly Model Templates2007200704VVDeals"
Dim t As Workbook
Dim s As String
Dim a As Window
.LookIn = OldPath
.SearchSubFolders = False
.Filename = "*.xls"
.MatchTextExactly = True
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
s = .FoundFiles(i)
I have 2 problems. First problem is that I am trying to add a function to make the window close once its finished printing. This actually works - but it limits my loop iterations from i = 1 to 2 (so it only runs 2 times and I'm not exactly sure why). If I don't include the statement - this can run for up to 7 - 8 times (these are very large files) then excel runs out of memory. Unfortunately, i can't set the loop to run from i = anything other than one.
So What I would prefer is to be able to make the "ActiveWindow.close" command work - because this way I can run the entire loop. But I'm not sure how to. I tried window referencing, I tried adding a new active Window so when the file opens, its opening in the active window already, but nothing works.
Preferably, I need to be able to reference both windows, as my next macro will involve referencing 2 windows (one static - always open) and the other the loop above.