The following code is not working like I thought it would. I've got 4 named cells on a worksheet, and if any of them are blank, I don't want the user to be able to print it. What am I missing? Is it something with my Cancel = True statement?
I’m launching a new workbook, exporting some stuff, basically creating a report. But then I want to add a BeforePrint event to the new worksheet. Both of the macro below works great right up until I change “Sheet1” to “ThisWorkBook”…then Excel crashes.
Sub AddCode1() Dim VBCodeMod As CodeModule Dim LineNum As Long Dim Copybook As Workbook Set Copybook = Excel.Workbooks.Add Set VBCodeMod = Copybook.VBProject.VBComponents("sheet1").CodeModule LineNum = VBCodeMod.CountOfLines + 1 VBCodeMod.InsertLines LineNum, "Private Sub Workbook_BeforePrint(Cancel As Boolean)" & Chr(13) & "if ActiveSheet.CodeName <> ""Sheet1"" or ActiveSheet.CodeName <> ""Sheet2"" or ActiveSheet.CodeName <> ""Sheet3"" then" & Chr(13) & "MsgBox(""This Electronic Outcome Review Summary Report is NOT optimized for Printing......................................
It shouldn't be this hard, from within an excel macro I am currently adding a new workbook and doing "some stuff" basically creating a report based on the first workbook.
In the new workbook I want to add a BeforePrint event to the ThisWorkBook Module. I can add it to other sheets, to code modules and other code to the thisworkbook module....but not the BeforePrint?
here is the code I've been working with, I also checked Chip Pearson's site and still can not figure it out.
the following code work on both PC and mac? It works fine on PC, but on mac the BeforeSave and BeforePrint code does not work and the SaveASheet code gets as far as opening and pasting the sheet but then is unable to save automatically.
Private Sub Workbook_BeforeClose(Cancel As Boolean) SaveASheet End Sub Private Sub Workbook_Open() Sheets("Open").Activate End Sub Sub SaveASheet() Dim fName As String Dim myPath As String Dim sht As Worksheet #If Mac Then..........
=OFFSET(Sheet1!$A$1,0,0,MATCH("PRINT_AREA_ROWS",Sheet1!$A:$A,0),MATCH("PRINT_AREA_COLUMNS",Sheet1!$1:$1,0)), lets say this equates to range("A1:D12")
I also have a workbook beforeprint event defined as follows:-
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.LeftFooter = "Pete" End Sub
My problem is that after the Print Event has fired , the dynamic range has been converted into a static one i.e range("A1:D12"). I have tried this on all version of Excel from 97 to 2007 and it behaves the same so premably this must be by design rather than a bug?
Am I doing something wrong? What is the work around? I'd rather not have to create the dynamic range within the print event procedure unless I have to as my workbook has many, many tabs!
Is it possible that when you press a command button, that the first thing it does is to execute the code assigned to another command button (IE in another sub).
Is there any way to tell (from VBA) what GUI command is currently in progress or what the last command used was?
On a wish list perhaps: Application.LastCommand and/or Application.CurrentCommand
Let's say I'm in the "Sheet_Change" event and want to know what caused the change. Was the event triggered by "Delete", "Paste", "Keystrokes" ...
AutoCAD VBA has "Begin_Command (CommandName as String)" and "End_Command (CommandName as String)" events which I find very useful. Basically I'd like to emulate that to the greatest extent possible.
Application.Caller does not seem to work for the stated purpose. I've been searching for a workaround by means of reading the "Undo Stack". Numerous articles written by experts state that the undo stack is not accessible from VBA.
I've considered reading the text from the "Undo" button's caption but it just seems like such a hack ... not that this whole idea isn't a hack
How can I return name of a command button on click? I want to create some sort buttons on a sheet I will use regularly to speed things up. I thought if I could call each sort button by the column letter the button sits in I can use this in a single sub for all buttons
e.g the button sitting in column A is called "A". when i click the button, it returns it's name to a variable which I can then use to sort column A. I know I could create a seperate routine for each button but I was just trying to think of something neater.
In this formula I want to be able to see if DEALLIST[Sales1], OR EALLIST[Sales2] is equal to $E$9, if they are then I want the formula to continue. I have tried this but it returns every row in my table starting from row 1 through 1000.
I have searched this topic but I came up with nothing regarding my exact situation.
I have 5 buttons on sheet 1. I want them to all direct me to another sheet in the same workbook. However, some buttons will contain more than one sheet.
Example: Button 1 will direct me to 4 different sheets. Is this possible?
Also, When I open the workbook, I see many sheets that I am working from but I do not want them to show up when I open the workbook. The only way to see these sheets is to click on the command buttons at the top of sheet 1.
I'm looking to have a doc where people time stamp their start and stop times. I have found that Control(apple) - Shift -semi colon works. The problem i'm having is that I want people to be able to use a command icon in their toolbars for this task as opposed to people have to use the keyboard. I can use a button with a macro but this is not possible as our excel corrupts when there are too many macro's
I have a sheet in which I have a sum then depending on this value I want the next cell, F4, to have one of four outputs
If the value in F3 is; Less than 1 F4 should show 9 between 1 and 2 F3 should show 16 Between 2 and 3 F3 should show 25 Greater than 3 F3 should show 36.
I have used IF to get the correct result when F3 is less than one but cannot work out how to add the other three results.
1. if I have a custom command Bar that is very long and I want it displayed in two rows how do I code it to start a new row at a certain point (button)? - can I control the length of it?
2. How do I make the Formatting toolbar inactive on opening a particular workbook?
I recorded this SQL query and got this and a Connection string, the query kind of works but i want to be able to edit more. Can someone tell me what does what in this huge string, i want to be able to edit the MatsViewerView.SpecType and other things like i can edit the lot number=2007312RC (very end of string). P.S. sorry about the formatting, i guess this is what excel does when it records a query onto a macro.
i need to merge several columns together with a comma seperator. but there are some columns with only set of data in and sometimes 6 columns with data. so i end of with something looking like WC,,,,, or GAU,MAJ,CHEM,,, etc. i have over 6000 lines so don't feel like cleaning up manually.
I need to find the row number of the first instance of the string 'TIMEACT in column A. I know that it must exist at some point in column A, but I do not know where. Column A might have 100,000 entries... ie: a very large number, so I'd appreciate it if the code could be very general.
I have a range of cells (A1:D5) identified within a worksheet (worksheetA) as part of a user input form.
When a certain condition exists, a routine is executed that copies a range of cells (C1:F5) from another worksheet (worksheetB) to this defined range. The copied area consists of two command buttons. They get copied and pasted no problem.
When I want to reset (blank it out of its contents) my range in worksheetA from I copy another range over of just a range of blank shaded cells. However, doing this does not eliminate the command buttons left in the range on previous pasting.
How do I delete these command buttons left from previous pasting activities when I wish to reset my range?
I have VBA code that hides and display columns. I have it coded in between Application.ScreenUpdating = False and Application.ScreenUpdating = True commands thinking that it will not show all the flashing and movement of columns.