excel-vba

VBA enums give occasional “Constant Expression Required” errors

无人久伴 提交于 2020-01-10 17:42:07
问题 I'm using an enum defined in a class module in Excel VBA. This has been working fine, but I've started getting a compile error on every time I do a comparison on enum variables: In class CExample: Enum MyEnum Foo Bar End Enum Elsewhere: If someValue = myEnum.Foo Then The text .Foo will be highlighted, and a "Compile error: Constant expression required" message pops up. A search on Google suggests that this can randomly happen, and fixes such as restarting the IDE or adding a space after the

Change printer properties in excel macro

跟風遠走 提交于 2020-01-10 10:27:12
问题 Is there any way I can change printer properties to color rather than black and white in an Excel macro/Excel VBA? I would like to print in color from the macro but every time I exit excel it sets the color to black and white. I would like for the macro to set the color back to color every time I run it. This is the code I am using to print: Workbooks("Book1.xlsm").Worksheets("Sheet3").PrintOut from:=1, To:=(i / 2) - 0.5 This prints every page effected by the macro but it does it in black and

Change printer properties in excel macro

萝らか妹 提交于 2020-01-10 10:24:32
问题 Is there any way I can change printer properties to color rather than black and white in an Excel macro/Excel VBA? I would like to print in color from the macro but every time I exit excel it sets the color to black and white. I would like for the macro to set the color back to color every time I run it. This is the code I am using to print: Workbooks("Book1.xlsm").Worksheets("Sheet3").PrintOut from:=1, To:=(i / 2) - 0.5 This prints every page effected by the macro but it does it in black and

VBA: How to display an error message just like the standard error message which has a “Debug” button?

大城市里の小女人 提交于 2020-01-10 07:54:30
问题 As usual, I create an error-handler using On Error Goto statement, there I put a few lines of cleaning codes and display the error message, but now I don't want to lose the comfortableness of the default handler which also point me to the exact line where the error has occured. How can I do that? Thanks in advance. 回答1: First the good news. This code does what you want (please note the "line numbers") Sub a() 10: On Error GoTo ErrorHandler 20: DivisionByZero = 1 / 0 30: Exit Sub ErrorHandler:

Compare cells to delete rows, value is true but not deleting rows

流过昼夜 提交于 2020-01-10 06:11:45
问题 I'm trying to compare 2 cells and if its true that row will be deleted, i tried using msgbox to return the value and it shows its true, but row is not deleting. The first cell is derived using formula in 1 sheet and the other is just numbers, does that make a difference? Dim r, s, i, t As Long Dim com, cc, bl, acc As Long Dim rDB, rInput As Range Dim shDB, shInput As Worksheet Set shDB = ActiveWorkbook.Sheets("Database") Set rDB = shDB.Range("A1", "T1000") Set shInput = ActiveWorkbook.Sheets(

Cannot seem to move worksheet's content reliably

﹥>﹥吖頭↗ 提交于 2020-01-10 05:51:09
问题 This is already part 4 of what has now become my 1st StackOverflow trilogy :) Hopefully bringing it all together will lead to an answer, or prove it cannot be handled. Quick summary (See the background for further details and conclusions.) I have an Excel workbook with a digitally signed VBA project, to be used by my customer. One of the functions it has is that the user can make copies of sheets (the templates), and my code can recognize the template sheets and the copies themselves (for

Getting Cell Values from Excel API C#

落爺英雄遲暮 提交于 2020-01-10 05:38:25
问题 I have a ribbon that i made for Excel along with a cs File to perform as the core of the add-in. When a button is clicked on the CustomRibbon I want to parse the data values for one of the rows. private void button1_Click(object sender, RibbonControlEventArgs e) { Console.WriteLine(Globals.ThisAddIn.Application.Cells[0, 0]); } But that gives me an error Exception from HRESULT: 0x800A03EC All i want to do is to be able to parse the data from cells on my worksheet and write data to the

Placing Double Quotes Within a String in VBA

时光怂恿深爱的人放手 提交于 2020-01-10 05:19:25
问题 I'm having a hard time understanding how to place a double quote (") within a String in VBA. I know that I can easily do this using the char(34) function. I also understand that another way of doing this is to use 4 double quotes: """" . All of this comes from a previous SO post: How do I put double quotes in a string in vba? However, my question is.... Why are 4 quotes needed? Do the first two act as the escape, the third is the quote itself, and the fourth is the terminating quote? Or does

“Application.Calculation = xlCalculationManual” statement causing run-time error 1004 in VBA Copy-Paste procedure

六眼飞鱼酱① 提交于 2020-01-10 05:17:07
问题 I have VBA code that copies the first row and pastes the values to multiple rows. The below code runs fine and pastes the rows as expected: Sub Macro1() Dim i As Long Application.Calculation = xlCalculationManual Range("A1:M1").Select Selection.Copy For i = 1 To 50 Range("A" & i).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Next i End Sub However, if I move Application.Calculation = xlCalculationManual down two lines as below,

How to extract text based on font color from a cell with text of multiple colors

浪子不回头ぞ 提交于 2020-01-10 05:16:45
问题 I have a column of data (A). The data in each cell in column (A) is half one color and half another color. For example, let's say the first portion of the character string is red and the second portion of the character string is black. The length of the red and black character strings within each cell varies with no pattern. The type of characters that are red and black vary with no pattern. There is no space or special character that separates the red characters from the black characters