I have written some code to search through excel sheets and return the values it finds. The code is written in a module, and when I run it by clicking the play button at the top of the VB editor it works perfectly.
However I have noticed that I need to link it to a button (on_Click) in sheet1, I have tried copying the code into the button sub, it throws up an error:
"Activate method of Range class failed"
Can anyone tell me why this code would work from its module and not when placed in the worksheet (the cells being activated are not empty).
I have some buttons in different sheets in an excel file, each button has its own code, that is the reason I can not move the code related to each object to another location (sheet or module).
And I have one piece of code in Module1 (Auto_load) in order to execute automatically this routine every time file is opened. Inside "auto_load" routine I initialize some values of some check buttons,options buttons and positions of some objects in diferent sheets, but I can not pass the value of variables between Module and Sheet's code even when I declare as public variables and/or function.
I have made a macro that displays a textbox containing the contents of a cell once the cell is clicked. The macro is written in the 'ThisWorkbook' module in the Sub 'Worksheet_SelectionChange'.
Now I want to convert this macro into an add-in so that it works on all the Excel workbooks I open. Is it possible to do this? Or is there a way in which we can automatically put the code in the 'ThisWorkbook' module of any open worksheet (doesn't seem feasible).
I have a spreadsheet with two modules. In an effort to reduce the file size of an archive, I’d like to remove some of the code (i.e., Module1). I have a macro that attempts to do this.
There are three parts to the operation. The first removes Module1; the second Quits the application; the third saves the changes. If I run each of these operations separately, it works fine. However, I’d like to do this with only one macro (SKK4). For some reason, it does not remove the Module. Here is my test Sub skk1() ThisWorkbook.VBProject.VBComponents.Remove_ ThisWorkbook.VBProject.VBComponents("Module1") End Sub
Sub skk2() Application.Quit End Sub
Sub skk3() ThisWorkbook.Close SaveChanges:=True End Sub
Somehow, from a fresh instal of Excel (to try and cure the same problem), and Insert Module, the box is green. Viewing a macro, the background is green, some of the code is black on green, but most is black or blue in white boxes cut out of the green. The code appears normal on another computer.
I have a problem deleting Module1 then saving the worksheet and keeping the module1 deleted. Without the rem'd code (shown below) a popup asks if you wish to save the changes; if you say "No" the module reappears in the file, and "Yes" the module stays deleted. Even with any of the Rem'd out code below the workbook is saved and closed, but on reopening the code module is still there. My problem is I don't want the user to have the choice, the workbook must be saved without the module. As this is a price quote program, with the module still in the Project, reopening and closing the saved workbook causes an error as the macro cannot find the deleted worksheets to delete! This is a very small test program for a much bigger one that has quite a bit of security in it.
Dim x As Object Application.DisplayAlerts = False
e = Sheets("Sheet1"). Range("B4") ' account name f = Format(Sheets("Sheet1").Range("B3"), "ddmmyy") ' date quote saved, cell = NOW() thisfile = e & "-" & "-" & f 'changed to name, Acc No, dat
I have a vba process that develops statistics/graphical output via SQL queries of pretty large datasets. This usually takes about 2min, so I run it via a form I've build, and then go do other work or play on the net, checking and rechecking if it has completed. I do have a msgbox once the process is complete, but if i am not actively in an Excel window, I will not see it. Is there a way to force the windows taskbar to flash or something so i can see that my process is complete if i am not in an Excel window?
how to write a procedure to delete macro code that is in the worksheet property? I created a and excel model for a colleague which had many macro procedures including "Worksheet_Activate". The problem is now this individual moves the worksheets into new workbooks and this is cause many runtime errors. Is there a way I can write a copy/move procedure that also deletes the Worksheet Activate macro so that error does not appear?
way to save user-settings at runtime, preferably in the same or another module. For example: how can I save a bundle of variables such that the next time excel is started and the workbook is opened, the user can continue to work with his personal settings?
Background: Using the macro, I am writing on atm, a user will be able to adjust the macro according to his input-samples. Here the columns and rows of an input can be varied to fit the macros requirements. It would be great if those settings could be stored, irrespectively of where the file currently resides. That is, best it would be, if the source-code itself could be changed ... maybe by adding another module?
One of the several ws is a form; when the user saves it, all other ws are deleted and the wb is saved as a new file name. (Need to retain other macros for future functionality, seems easiest to just delete the unneeded sheets).
Is their a way to modify the sheet reference from "menu" to "sheet-name" (will be a constant). Because it is likely that additional sheets will be added in the future to this new wb, I'd like for it to open to a specific ws.
As my VBA skills are "in development" (basement level, just now), please provide a complete answer (assuming this can be done).
I am trying to create a new sheet from an existing sheet. I only need to copy the sheets and not the code from the original sheet. But, when I copy the first sheet the code module also gets copied to this new sheet.
I have a workbook which I regularly upload that cannot have macros within it; however, to update and process the data, I must utilize VBA Code.
I tried to work around this by storing my macros in a module in another workbook. My process is to have the VBA Code Module from the other workbook open and have the active workbook be the one I want to change, then I run the VBA Code from the other workbook.
This used to work. However, I am recently getting problems with the Code not running correctly. Sometimes it only runs the code if the affected cells are not hidden; other times it will not run the code at all!
I want to delete the contents of every cell without deleting any code from my module. The reason I ask is, I'm reading from a text file into excel.
I want to run my code to read text into excel one time through. Then i want to delete all the text, make some alterations to my code, and run the code again. That way each time the worksheet is fresh and clear before i run the code.
I have previously used the following code to successfully pull out IE webpage source code for string manipulation.
Its a crude example to demonstrate the principle:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public IE As Object Sub Sample() Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True
However when I substitute in a Google websites address into the IE.Navigate command, the code runs to the "Source_Code = IE.document ...." line then flags up a Microsoft Visual Basic error. "Run-time error '438': Object doesn't support this property or method"
The webpage that I am trying to access is a confidential company site, so you won't be able to access it yourself, but starts with [URL] ......
The one thing that I have noticed about this website is the Privacy Report icon in the lower right status window (Picture of an eye with a restricted symbol in front). I don't know whether this is the cause of my problem, or purely an incidental observation.
Is there something peculiar with Google sites that means that the source code cannot be extracted in general, or is this an issue specific to my site ? Does the Privacy Report icon have any relevance, and if so how do I switch that off ?
After all the awesome macros I've obtained with the help of all of you, I now have over 30 macros, each in its own module. I have tried without success to re-name the modules with no luck. How is everyone organizing these?
What i have at the moment is a module that contains code where i call a different module that i use as a procedure.
Code: If Sheet1.Range("C4").Value < Sheet1.Range("A2").Value Then If Sheet1.Range("K4") = "" Then MsgBox "Please check 06:00 tasks not done yet!" Cell = "Range(" & Chr(34) & "F4" & Chr(34) & ")" If Sheet1.Range("C4") + 0.042 < Sheet1.Range("A2") Then Run "EmailProSheet" End If End If End If
EmailProSheet is what i call but now i want to use the variable "Cell" in the procedure as well?
Code: MsgBox Cell Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next
As it is now everything is working fine but does not return a value in "Cell" if the procedure is called. Is there another way?