excel-vba

How to fix run time error 424 when accessing the value of a CheckBox in Excel VBA?

时间秒杀一切 提交于 2020-01-26 02:02:25
问题 Okay so here is the problem: In my user form, I have 2 checkboxes. I want to be able to use the value of the checkbox to perform a certain job. Example: Sub main() UserForm1.Show If UserForm1.CheckBox1.Value=True Then MsgBox("Awesome") End If End Sub Now my problem with this is that it keeps giving me run time error 424. Can anyone help me with this? Your help is greatly appreciated. Thank you. Update: Sub main() UserForm1.Show If UserForm1.CheckBox1.Value=True Then Worksheets(1).Activate If

VBA to create password protected file

[亡魂溺海] 提交于 2020-01-26 01:28:09
问题 With the below coding, I am able to create a copy of password protected file. But I also want to put the password in newly created file. How can I add password while creating new excel workbook. Workbooks.Open Filename:=myFileNameDir, Password:="yourpassword", UpdateLinks:=0 Set ws1 = Worksheets("OJT Plan") ws1.Activate filen = TextBox3.Text & "_" & TextBox59 & "_" & VBA.Format(Now, "MMddyyyyhmmss AM/PM ") ws1.SaveAs Sheet1.Range("V3").Value & filen & ".xlsx" Worksheets.Add(after:=Worksheets

VBA: Runtime Error - SetSourceData for Second Pivot Chart

只谈情不闲聊 提交于 2020-01-25 23:50:50
问题 I am getting: Run-time error '-2147467259 (80004005)': Method 'SetSourceData' of object '_Chart' failed intermittently when I try to run the following script: Sub CreatePiePivot() 'Define worksheets Set PSheet = Sheets("Tools") Set DSheet = Sheets("Aggregate") 'Define last data points LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column 'Selects first to last filled row, and first to last filled column for data Set PRange = DSheet

Color consecutive higher cells

泪湿孤枕 提交于 2020-01-25 23:05:24
问题 I am trying to create a macro that color cells that are higher than the previous one. I want to color only cells that follow a serie of 5 cells each one hiher than the previous one. In this screenshot, if I have such a series, only D14 should be colored in red, because D14>D13>D12>D11>D10>D9. In other terms, because from D9 to D13, the 5 cells are always higher than the previous one. This is my code but it is not working: Sub Consecutive_HigherCells() Dim i, j As Integer For j = 1 To 5 If

How do I reference an Excel ListObject table column if the column name has line breaks?

给你一囗甜甜゛ 提交于 2020-01-25 23:00:11
问题 I'm tasked with the following: several sheets from different workbooks have to be copied to a new workbook each of those sheets contains an Excel table (a ListObject), named like the sheet with a postfixed T (sheet Foo, table: FooT) the new workbook has to contain a summary sheet where each table name is listed, and various values of the respective tables are presented by referencing them with suitable formulas This has to be done frequently for different workbooks, so the idea was to do this

Pulling data from PI DataLink using VBA

筅森魡賤 提交于 2020-01-25 21:49:25
问题 I am pulling huge amount of data from PI Server using VBA. I am using the following code: **Dim myValues As PIValues Set myValues = PIMath.GetInterpolatedValues_Point(inputPIPoint, PIMath.StringToPITimeFormat(StartDate), PIMath.StringToPITimeFormat(NextDate), "10s")** What is the fastest way to copy all the values stored in MyValues to a column in a worksheet? I am using For Loop: For k = 1 To myValues.Count Worksheets("Sheet6").Cells(k, 2).value = myValues(k) But it is extremely slowing down

Excel Add .xlam module inject code into new sheet

无人久伴 提交于 2020-01-25 21:14:48
问题 I have a module which is creating a sheet. It builds a worksheet with a series of tables. I'd like to add a feature that uses the OnChange event for a cell to validate that the user entered a decimal. The following code does this If I can just inject into the new worksheet . That's the only thing I can't figure out. Given 's' is the current Worksheet we've just created is there any way to inject the following code into the sheet code module of 's'? Private Sub Worksheet_Change(ByVal Target As

Excel Add .xlam module inject code into new sheet

倖福魔咒の 提交于 2020-01-25 21:14:11
问题 I have a module which is creating a sheet. It builds a worksheet with a series of tables. I'd like to add a feature that uses the OnChange event for a cell to validate that the user entered a decimal. The following code does this If I can just inject into the new worksheet . That's the only thing I can't figure out. Given 's' is the current Worksheet we've just created is there any way to inject the following code into the sheet code module of 's'? Private Sub Worksheet_Change(ByVal Target As

list specific file type in directory using excel 2010 vba

寵の児 提交于 2020-01-25 21:13:53
问题 In an excel 2010 vba I am trying to list all .txt files in a specific directory and display them in a message prompt. I hope the below is a good start, but not sure. Thank you :). vba ' LIST ALL TEXT FILES IN REPORT DIRECTORY ' Const strFolder As String = "C:\aCGH\" Const strPattern As String = "*.txt" Dim strFile As String strFile = Dir(strFolder & strPattern, vbNormal) Do While Len(strFile) > 0 Debug.Print strFile strFile = Dir Loop MsgBox "The files are " + strFile 回答1: Two ways I can

VBA not Recognizing MAPI

两盒软妹~` 提交于 2020-01-25 20:57:43
问题 I'm using VBA to enter into an outlook folder and put the message body into a cell. However on set ns = getnamespace("MAPI") I get an error "automation error library not registered". I have the following outlook related references selected (within Excel): Outlook 14.0 Object Library, Outlook SharePoint Social Provider, Outlook Social Provider Extensibility, Outlook View Control I'm using Excel 2010. The entire code follows. Any help would be greatly appreciated. Dim ns As Namespace Dim inbox