excel-vba


Nested collections, access elements type mismatch

左心房为你撑大大i 提交于 2020-02-29 06:10:48
问题 I have two collections, the second one is inside the first one. But when I try to access the element of the second collection I get a Type mismatch error. Sub testColls() Dim coll1 As Collection Dim coll2 As Collection Set coll1 = New Collection Set coll2 = New Collection coll2.Add ("dog") coll1.Add ("cat") coll1.Add coll2 Dim temp As String temp = coll1(1)(1) MsgBox (temp) End Sub Why is this error? coll1(1) gets the second collection, coll (1)(1)` should give first element of the second

Nested collections, access elements type mismatch

扶醉桌前 提交于 2020-02-29 06:07:49
问题 I have two collections, the second one is inside the first one. But when I try to access the element of the second collection I get a Type mismatch error. Sub testColls() Dim coll1 As Collection Dim coll2 As Collection Set coll1 = New Collection Set coll2 = New Collection coll2.Add ("dog") coll1.Add ("cat") coll1.Add coll2 Dim temp As String temp = coll1(1)(1) MsgBox (temp) End Sub Why is this error? coll1(1) gets the second collection, coll (1)(1)` should give first element of the second

How to reference a workbook from another excel instance

回眸只為那壹抹淺笑 提交于 2020-02-28 19:02:26
问题 I believe my problem is rather simple: I have a workbook and I'm using it to get some data from another software (SAP). When I export the data from the software, it automatically opens a .xlsx file, then what I'd need to do is copy some of the data from this file, paste on my original workbook, and then close the file. The section of my code which is giving me an error is this one: fileName = "temp1.xlsx" Set wbBasis = Workbooks(fileName) This happens because the "temp1.xlsx" file that was

Excel VBA - Get name of table based on cell address

微笑、不失礼 提交于 2020-02-28 07:29:33
问题 I am using Excel and am looking to get the name of the table based on a cell address (ex A3), this cell will not move. How would I go about stating this in Excel's VBA? My plan is to have code that will copy data validations from a row of one table on my Maintenance tab to a single table on each tab of my workbook (minus my "TOC" and "data" tabs). Each tab is a copy of a "TEMPLATE" worksheet (minus the "TOC", "data", & the "TEMPLATE (Maint.)" worksheets). Worksheets "data", "TEMPLATE", and

VBA Text-To-Columns Reading Date Format As US

左心房为你撑大大i 提交于 2020-02-28 06:51:07
问题 When running text-to-columns in vba, it puls my dates as american dates, instead of uk dates, as long as it is possible for it to do so. So for example, 31-Aug stays as 31-Aug, but 01-Sep changes to 09-Jan! Is there any way to specify that all dates are in UK format BEFORE vba runs? As even just reformatting to US dates to show as US dates won't work because we have code that runs if date < Today , which of course will cause issues with the changing date format. The data feeds in the format

How to exclude 1 sheet from my save to pdf VBA macro

南楼画角 提交于 2020-02-25 12:55:16
问题 I have a VBA code that works well, apart from the fact that i don't know how to exclude one sheet from saving to the PDF. I would like the exclude the sheet named 'Control' from being included in the export and save to PDF. Any ideas how or where i should add this? Thanks Sub CreatePDF() Dim saveAsName As String Dim WhereTo As String Dim sFileName As String Dim ws As Worksheet Dim myrange ' Retrieve information from Control sheet Sheets("Control").Activate Range("C4").Activate periodName =

How to exclude 1 sheet from my save to pdf VBA macro

折月煮酒 提交于 2020-02-25 12:54:25
问题 I have a VBA code that works well, apart from the fact that i don't know how to exclude one sheet from saving to the PDF. I would like the exclude the sheet named 'Control' from being included in the export and save to PDF. Any ideas how or where i should add this? Thanks Sub CreatePDF() Dim saveAsName As String Dim WhereTo As String Dim sFileName As String Dim ws As Worksheet Dim myrange ' Retrieve information from Control sheet Sheets("Control").Activate Range("C4").Activate periodName =

How to know the procedure by which subroutine called? in excel vba

落爺英雄遲暮 提交于 2020-02-25 05:51:05
问题 I sometimes has error on subroutine.The subroutine is called by many procedure. So, I try to find caller procedure for step over. By the way, user-defined function can know the caller. It is simply. MsgBox Application.Caller We can see dialog and caller cell address. I want to know caller procedure of subroutine. 回答1: You can use Call Stack Dialog Box For example in the below image proc3 was called by proc2 which is displayed in call stack dialog box. 来源: https://stackoverflow.com/questions

Sentry objects in VBA

感情迁移 提交于 2020-02-25 01:30:53
问题 I see codes with the following pattern ubiquitously on the web and in my own projects: Sub Func() Application.EnableEvents = False ' some code Application.EnableEvents = True End Sub Since the lifetime of VBA objects seems to be deterministic, I thought I could replace this pattern with the so-called sentry objects as we do in C++ , so that the problem of unusual exit (err.raise) could be solved automatically. But how? I have little idea because I'm new to VBA and not even fully aware of when

Automatically adapt listbox column width

独自空忆成欢 提交于 2020-02-25 00:38:42
问题 I programmatically add elements from a database to a multicolumn listbox using this code : Do While (Not rs.EOF) ExistingSheetsListBox.AddItem ExistingSheetsListBox.List(i, 0) = rs.Fields(0) ExistingSheetsListBox.List(i, 1) = rs.Fields(1) ExistingSheetsListBox.List(i, 2) = rs.Fields(2) ExistingSheetsListBox.List(i, 3) = rs.Fields(3) ExistingSheetsListBox.List(i, 4) = rs.Fields(4) i = i + 1 rs.MoveNext Loop The insertion in the listbox works fine, but the column width is not always adapted to

工具导航Map