excel-vba

VBA Code to select Sender and Signature

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-30 04:44:05
问题 In Excel I'm using code like this to begin an e-mail message through Outlook: Set mOutlookApp = GetObject("", "Outlook.application") Set OutMail = mOutlookApp.CreateItem(0) With OutMail .To = "blahblah@blah.com" .Subject = "More BLAH here" .HTMLBody = "Message Text" & .HTMLBody ' This preserves the Signature in the message. .Display End With Normally, when I send a (manual) e-mail, I can choose to send it from an address other than my normal one (by pressing the "From" button). Also, I can

Excel VBA error handling not working for second error

佐手、 提交于 2020-04-16 08:44:10
问题 In the below code Errorhandler correctly takes care of first error when I enter a workbook that is not open or any random string. But when I click on retry and again enter a random name I get " Subscript out of Range " error @ Workbooks(workbookname). Activate. Can anyone help me why it is happening and how can I make it work. I have tried a lot of things. But nothing is working. This code is part of a larger program. Sub test() Dim workbkname As String On Error GoTo Errorhandler Retry:

Excel VBA error handling not working for second error

折月煮酒 提交于 2020-04-16 08:43:27
问题 In the below code Errorhandler correctly takes care of first error when I enter a workbook that is not open or any random string. But when I click on retry and again enter a random name I get " Subscript out of Range " error @ Workbooks(workbookname). Activate. Can anyone help me why it is happening and how can I make it work. I have tried a lot of things. But nothing is working. This code is part of a larger program. Sub test() Dim workbkname As String On Error GoTo Errorhandler Retry:

Select range of sheets in Excel VBA

谁都会走 提交于 2020-04-14 09:10:16
问题 I'm trying to select a range of worksheets in an Excel macro, so that they can then be printed. I want to print a range, i.e. Sheet2-Sheetx, where x is a variable. I have tried recording a macro to do what I want, but it uses sheet names rather than sheet references, and of course doesn't support variables. In this example, I selected three sheets, so x=3: Sheets(Array("Data", "Data (2)", "Data (3)")).Select ActiveWindow.SelectedSheets.PrintOut preview:=True I would have thought this would be

Select range of sheets in Excel VBA

大城市里の小女人 提交于 2020-04-14 09:07:30
问题 I'm trying to select a range of worksheets in an Excel macro, so that they can then be printed. I want to print a range, i.e. Sheet2-Sheetx, where x is a variable. I have tried recording a macro to do what I want, but it uses sheet names rather than sheet references, and of course doesn't support variables. In this example, I selected three sheets, so x=3: Sheets(Array("Data", "Data (2)", "Data (3)")).Select ActiveWindow.SelectedSheets.PrintOut preview:=True I would have thought this would be

Selecting a shape in Excel with VBA

左心房为你撑大大i 提交于 2020-04-14 07:48:53
问题 I am trying to select a shape by name using VBA. In my sheet, I have 10 shapes named 1 to 10 and want a specific one. For some reason, the shape that excel selects with my code does not seem to be the shape with the name I told it to select. As far as I can tell, the shape that it chooses is random. Here is my code (The x value is supposed to retrieve a number value that I input from 1 to 10): Sub FindTheShape() Sheets("Fleet 1").Select Dim x As Long x = ActiveSheet.Range("$A$1000").End(xlUp)

check if array is empty (vba excel)

蹲街弑〆低调 提交于 2020-04-12 20:46:03
问题 These if ... then statements are getting the wrong results in my opinion. The first is returning the value 'false' when it should be 'true'. The fourth returns the right value. The second and third return an error. Sub empty_array() Dim arr1() As Variant If IsEmpty(arr1) Then MsgBox "hey" End If If IsError(UBound(arr1)) Then MsgBox "hey" End If If IsError(Application.match("*", (arr1), 0)) Then MsgBox "hey" End If ReDim arr1(1) arr1(1) = "hey" If IsEmpty(arr1) Then MsgBox "hey" End If End Sub

check if array is empty (vba excel)

…衆ロ難τιáo~ 提交于 2020-04-12 20:38:43
问题 These if ... then statements are getting the wrong results in my opinion. The first is returning the value 'false' when it should be 'true'. The fourth returns the right value. The second and third return an error. Sub empty_array() Dim arr1() As Variant If IsEmpty(arr1) Then MsgBox "hey" End If If IsError(UBound(arr1)) Then MsgBox "hey" End If If IsError(Application.match("*", (arr1), 0)) Then MsgBox "hey" End If ReDim arr1(1) arr1(1) = "hey" If IsEmpty(arr1) Then MsgBox "hey" End If End Sub

check if array is empty (vba excel)

▼魔方 西西 提交于 2020-04-12 20:38:11
问题 These if ... then statements are getting the wrong results in my opinion. The first is returning the value 'false' when it should be 'true'. The fourth returns the right value. The second and third return an error. Sub empty_array() Dim arr1() As Variant If IsEmpty(arr1) Then MsgBox "hey" End If If IsError(UBound(arr1)) Then MsgBox "hey" End If If IsError(Application.match("*", (arr1), 0)) Then MsgBox "hey" End If ReDim arr1(1) arr1(1) = "hey" If IsEmpty(arr1) Then MsgBox "hey" End If End Sub

Convert VBA to Javascript (Google Apps Script)

99封情书 提交于 2020-04-12 07:41:29
问题 I would like to convert my VBA to something I can use for Google Apps Script. Sub Macro5() ' ' Macro5 Macro ' ' Range("B2").Select Selection.Copy Range("B15").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False Rows("15:15").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("B2").Select End Sub And I ended up with this: function Macro5(){ Range("B2").Select; Selection.Copy;