vbe

How do I get the *actual* host application instance?

回眸只為那壹抹淺笑 提交于 2019-12-10 17:16:51
问题 I have this code in a C# add-in for the VBE (emphasis "VBE": it's not a MS-Office add-in): public abstract class HostApplicationBase<TApplication> : IHostApplication where TApplication : class { protected readonly TApplication Application; protected HostApplicationBase(string applicationName) { Application = (TApplication)Marshal.GetActiveObject(applicationName + ".Application"); } Where TApplication is a MS-Office interop Application class, for example, a Microsoft.Office.Interop.Excel

Why do I need to have the VBA editor open to load data into a Userform?

半世苍凉 提交于 2019-12-10 12:34:38
问题 I have an Excel file in which a VBA macro loads data into a Userform. It will sometimes crash and close Excel if I run it without the editor open. How to fix my file so I don't need to first open the editor? Sample code from the macro: Public Sub LoadButton_Click() 'Policy Information ZoneLatitudeTextBox.Text = Sheets("Saved Policy Values").Cells(2, 2) ZoneLongitudeTextBox.Text = Sheets("Saved Policy Values").Cells(3, 2) TownClassComboBox.Text = Sheets("Saved Policy Values").Cells(4, 2) 回答1:

Event raised when closing or opening a CodePane

落花浮王杯 提交于 2019-12-10 10:36:54
问题 I'm writing a VBE/VBIDE add-in and I have a tool window that changes based on the open CodePane objects. Is there an event I can monitor when a code pane is added or removed from the CodePanes collection? The CodePanes collection itself appears to have no Events associated with it. If there is no event available, I'm open to other workarounds. Polling would be a reliable fallback, but I'd rather not go that route if I could avoid it. 来源: https://stackoverflow.com/questions/44391917/event

Is there VBA syntax highlighting for opening and closing loops and if statements?

一笑奈何 提交于 2019-12-08 00:44:02
问题 Sorry if this has been asked before but I can't seem to find any information on this. I am working with VBA for automating word documents and I have this huge block of code with tons of "if else" statements, "do while" loops and "with" statements all nested together. When I program using other languages and other IDE's, I can normally click the opening "if" or "while" bracket and get the highlighted closing bracket. This makes it a lot easier to keep track of everything. Is there anything

Where are the VBProjectsEvents?

倖福魔咒の 提交于 2019-12-07 04:40:52
问题 Using Microsoft.Vbe.Interop in C#, I can access CommandBarEvents and ReferencesEvents via VBE.Events . However the ever-so helpful MSDN documentation seems to indicate that there's a VBProjectsEvents that I could use to notify my add-in when a project is added or removed to/from the VBE... which is exactly what I'm trying to achieve here. I can see that _VBProjectsEvents interface in the object browser , but no implementation for it (as opposed to the _CommandBarControlsEvents interface,

How do I know that `ThisWorkbook` is a `Workbook`?

戏子无情 提交于 2019-12-06 23:01:29
问题 I'm working with the VBIDE API, and can't assume that the host application is Excel, or any Office app either. So all I know is that I'm looking at a VBComponent , and that its Type is vbext_ct_document . In the VBE's immediate pane I can get this output: ?TypeName(Application.VBE.ActiveVBProject.VBComponents("Sheet1")) VBComponent ?TypeName(Sheet1) Worksheet But the Sheet1 object only exists in the runtime environment, so if I'm a C# add-in I don't even see it. The only thing that gets

Rubberduck UI submenus are disabled

限于喜欢 提交于 2019-12-06 17:29:16
问题 I've just installed the Rubberduck VBE add-in v2.0.11.2453 (MSIL) on Windows 10 OS. When I open a macro-enabled Excel workbook in Excel and launch the VBA editor, Rubberduck starts but all commands under the Rubberduck menu are disabled. What am I doing wrong? 回答1: Disclaimer: I'm heavily involved with the development of the Rubberduck add-in. You did nothing wrong =) In earlier alpha 2.x releases we discovered that launching the initial parse on startup was causing problems (violent crashes)

Event raised when closing or opening a CodePane

六月ゝ 毕业季﹏ 提交于 2019-12-06 11:42:25
I'm writing a VBE/VBIDE add-in and I have a tool window that changes based on the open CodePane objects. Is there an event I can monitor when a code pane is added or removed from the CodePanes collection? The CodePanes collection itself appears to have no Events associated with it. If there is no event available, I'm open to other workarounds. Polling would be a reliable fallback, but I'd rather not go that route if I could avoid it. 来源: https://stackoverflow.com/questions/44391917/event-raised-when-closing-or-opening-a-codepane

VBA Error Handler that emails me when errors occur

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 10:49:06
问题 I have created an error handler for a larger program that will email me when an error occurs which includes what line the error is happening on and the code for the whole function/sub that it happen in. The issue is that this code relies completely on having line numbers for every line in the code. I want to recreate this function without having to revamp line numbers whenever I make a change. Does anyone have any suggestions? Here is what I am using now: Public Sub EmailErrror(e As ErrObject

VBA - IE GetElementByID not working

为君一笑 提交于 2019-12-05 23:57:42
问题 I'm having some trouble with entering a text in a search box when after I what I think to be the correcet ID tag is. I got the ID from the page's source code. I've done this before with other websites. Can someone please help me out? Is there another way to do this? Sub FileUpload() Dim IEexp as Object IEexp.visible = True IEexp.Navigate ("www.example.com") 'this is where the problem IEexp.Document.GetElementByID("step1_id_bean_newSupportingDoc_description").Value _ = "monthly update" End Sub