vbe

How to automate find/replace code in VBA modules in MS Office 2013?

纵然是瞬间 提交于 2019-12-21 23:26:18
问题 I have a large number of Excel Templates that contain VBA code that need to be updated. The Find method of the code-module object only returns true/false, not the location of the found string. Is there any way to automate the find-and-replace procedure? 回答1: Add this code to a new macro-enabled workbook. Set the FIND_WHAT and REPLACE_WITH constants, open the other workbooks and run the code. The original code comes from Charles Pearson's site WARNING: Only basic testing has been done! Option

Is there a way in VBA to know about variables that aren't being used? [closed]

。_饼干妹妹 提交于 2019-12-21 03:36:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there a tool, method or setting in the standard VBA Editor to warn about variables that have been Dim 'med, but aren't being used? 回答1: MZ-Tools will search through your code and tell you what is not being used. The version for VBA can be found here. The specific feature in MZ-Tools that performs what you

Why does this code compile when pasted in but fail otherwise?

南楼画角 提交于 2019-12-18 19:09:06
问题 A friend made me look at this page, and noticed a strange piece of code in the signature of one of the forum users. The code is a one-liner that goes as follows: On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0 Scrolling removed: On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False)

How to programmatically change conditional compilation properties of a VBA project

只愿长相守 提交于 2019-12-18 02:18:38
问题 I'm currently working on a VBA code generator/injector that adds VBA functionality to Excel workbooks by using the VBA Extensibility. This all works fine. However, the original code that is injected uses conditional compilation, referring to some global conditional compilation arguments: Is there any way I can programmatically modify/add the conditional compilation arguments of a VBA project? I checked all properties of the VBProject but couldn't find anything. 回答1: Inspired by this approach,

Use Python to Inject Macros into Spreadsheets

风流意气都作罢 提交于 2019-12-17 10:43:03
问题 I've got a macro that I'd like a bunch of existing spreadsheets to use. The only problem is that there are so many spreadsheets that it would be too time consuming to do it by hand! I've written a Python script to access the needed files using pyWin32, but I can't seem to figure out a way to use it to add the macro in. A similar question here gave this answer (it's not Python, but it looks like it still uses COM), but my COM object doesn't seem to have a member called VBProject: Set objExcel

Copy VBA code from a Sheet in one workbook to another?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 10:34:29
问题 I've been using the lines below to compy VBA modules from one workbook to another and I don't know if there is an easier way, but they have been working fine: Set srcVba = srcWbk.VBProject Set srcModule = srcVba.VBComponents(moduleName) srcModule.Export (path) 'Export from source trgtVba.VBComponents.Remove VBComponent:=trgtVba.VBComponents.Item(moduleName) 'Remove from target trgtVba.VBComponents.Import (path) 'Import to target However now I need to copy VBA code that is in a Sheet, not in a

Userform toolbox additional controls dialogue window not showing

て烟熏妆下的殇ゞ 提交于 2019-12-11 11:24:06
问题 While using MS Excel (Outlook, Word, or Power Point as well apparently) I create a userform. The toolbox shows up showing controls tab and 16 icons representing various controls. When I right click in some empty space in the tool box control area, a menu comes up listing "additional controls" at the top and two greyed out options below it. When I select "additional controls" a spinning blue circle appears briefly then disappears and nothing happens. It is my understanding that a dialogue box

Can VBE be invoked/used OUTSIDE of an Office Application?

心不动则不痛 提交于 2019-12-11 02:17:34
问题 This may be a silly question - I haven't found anything on Google about this. No new programs populate in the task manager when VBE is opened from an Office Application, and I don't see an executable that looks probable. DLL maybe? 回答1: Some Office applications provide the Run method for the Application class. For example, see Run Excel Macro from Outside Excel Using VBScript From Command Line. Yes, you can call VBA macro at runtime. There are applications that don't provide any specific

Application.Cells VS Application.ActiveSheet.Cells

☆樱花仙子☆ 提交于 2019-12-10 18:34:32
问题 The Macro Recorder generated the following statement: Cells.Select Now I understand that without the object qualifier this will return all the cells as a Range object. However, I am wondering what the fully qualified version of this statement is? Is it: Application.Cells.Select Application.ActiveSheet.Cells Application.ActiveWorkbook.ActiveSheet.Cells In other words, which one of those fully qualified statements is actually executed by VBE when it runs Cells.Select ? What is the difference

Can I get the text of the comments in the VBA code

浪尽此生 提交于 2019-12-10 17:26:26
问题 Lets say I have the following: Public Sub Information() 'TEST End Sub Is there a way to get "TEST" as a result? Somehow through VBA? E.g. - In PHP there is a good way to take the comments. Any ideas here? Edit: There should be a way, because tools like MZ-Tools are able to provide the comments when they generate the documentation. 回答1: After some tests, I got to this solution: simply pass the name of the code-module to the function and it will print all comment lines. Inline comments won't