To Execute VBA Code @ 9:30:01 Exactly
Dec 27, 2008
Using Excel 2003 with WinXP. I'm trying to run macro code automatically whenever time = 9:30:01 (or whatever time I pick) for a stock market trading program, which is why the exact time matters so much. I've been able to get the time to update fine, but unless I click on the worksheet while the time condition is TRUE then my code doesn't run. The time actually is sent to me from the stock data provider and it shows up in a cell as a constantly updating value.
I've tried using the Workbook_SheetChange function and OnTime method, but without luck.
In both cases, unless I activate the sheet the code doesn't run. By activate, I mean that I have to click on the sheet when the values that trigger the code to run would be true. If I do that it works just fine, but sitting around and clicking on a worksheet defeats the purpose of automation. Since I'm trading stocks this has to be very exact, so I can't trust a macro scheduler to do this.
The code further below is what I'm trying to get to run. The time value is in cell L1. In cell L2 I have the following
View 9 Replies
ADVERTISEMENT
Jan 4, 2008
Assume a cell -- say A1 -- has a long formula in it. If I select A1, press F2 to "Enter" the cell, then I have a blinking 'l' indicating the cursor/pointer position WITHIN the cell.
Is there any way to control the position of the blinking 'l' (or whatever it is called)? For instance, in a long formula, I would like to write a macro which could transport the blinking 'l' to midway into the formula string.
Alternatively, can I make a partial selection WITHIN a cell and run a macro on it. For instance, if cell B1 has a heading "Dec 2007" and I highlight just the "Dec" portion of the string, I would like to execute a macro to color it red. I have a simple macro that can do it to the entire cell, but not to only part of the cell contents. Is there any way for VBA to be active when I am WITHIN a cell.
Sub Font_Red()
'will add red color to ActiveCell font
Selection.Font.ColorIndex = 3
End Sub
View 9 Replies
View Related
Mar 30, 2007
how could I use string to execute VBA. For example
x=10
mystring1="for i =1" & " to " & CStr(x)
mystring2="msgbox i"
mystring3 ="next i"
execute mystring1 & mystring2 & mystring1
Like this, I want to combine a VBA CODE string.
And use this string to execute VBA
View 5 Replies
View Related
Nov 7, 2012
I have below code to open DOS from excel. it is working fine.
I wanted to excecute some DOS command automatically after opening DOS, command is entered in the excel Sheet1 E5:E1000
Sub openDos()
Call Shell("cmd.exe " & dosCmd, vbNormalFocus)
End Sub
View 4 Replies
View Related
May 10, 2007
I want to execute the following code once for each day (Mon to Sun)
Dim Day As String
Dim DeletedDept As String
Set StartRange = Cells(Range("Cashiers").Row + 1, Range(Day & "_Date").Column + 1)
Set EndRange = Cells(Range("Cashier_Totals").Row - 1, Range(Day & "_Date").Column + 3)
Set EntryRange = Range(StartRange, EndRange)
For Each cl In EntryRange
If cl.Value = DeletedDept Then cl.Value = ""
Next
View 3 Replies
View Related
Sep 19, 2007
I have some code that launches a msgbox and I would like to have the code continue to execute with the msgbox displayed rather than wait for the user to click OK/Cancel.
View 9 Replies
View Related
Jul 22, 2014
Is it possible to write a macro that can import VBA code in a text file then execute it? I need this functionality as I have produced a corporate spreadsheet template that goes out to many people and I will need to be able to update it as requirements change once it has been distributed. So my idea was to build a macro in the template that has the code in it to import the "update code" from a text file that I would send to all the folks that have the template. If the template was centralized, that would save me from this issue but it is however going to be distributed widely.
View 5 Replies
View Related
Oct 28, 2009
I would like to write the code or create a macro that will execute when the value of a range of cells is greater than null. The macro or code that I would like to execute will UNHIDE a group of consecutive rows.
View 14 Replies
View Related
Feb 20, 2013
I've attached a sample workbook in which there are 3 macro-buttons.
The buttons will paste a shape in the active cell. So this means the buttons themselves could be deleted and replaced with a shape.
Since locking and then protecting the cells disables the macros, how can I amend the code to make sure the buttons' cells are protected from the copying and pasting macros? Or, how do I ensure that the macros only work in A1 - E5?
View 4 Replies
View Related
Jul 6, 2009
I have recently used a before_close event on this workbook to save a backup of the open file to another location on my system. This works fine but I was wondering if there was some more code I could add to only execute this event on a write access basis.
The file I use can be viewed by anyone on the network as read-only and only certain users with a password can edit/update with a write access password.
The backup event is use executes every time the document is closed be it read-only or write-access.
Ideally I would like to add some code to only execute this backup if the file is opened on a write-access basis.
View 3 Replies
View Related
Sep 5, 2013
I need to be able to hide and unhide a given set of rows based on the value in a particular cell. My current code allows me to successfully do this, ONLY, when I select the cell being 'watched' for changes and press enter. It does not execute the code automatically.
The cell is changed by a set of filters that modifies the data. The watched cell is then a summation of the filter modified cells. If the filters change to all "0" or "-" then my 'watched' cell sum becomes "0" and thus should execute the code automatically.
Current Code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Outline.ShowLevels RowLevels:=3
If Range("I62").Value = "0" Then
Rows("63:87").Hidden = True
End If
End Sub
So, right now if I use the filter and the cells change then the sum in I62 becomes "0", I have to manually select cell I62 and press enter and which point the above code executes exactly as I intend.
I need the execution part to be automatic and not have to manual click into cell I62.
View 1 Replies
View Related
Feb 28, 2014
I have the following code:
[Code] .......
What do I need to change in order to make it execute the Call statement on EVERY item in the ListBox2, not the Selections.
View 3 Replies
View Related
Apr 14, 2009
Is it possible that when you press a command button, that the first thing it does is to execute the code assigned to another command button (IE in another sub).
View 9 Replies
View Related
Feb 20, 2007
Is there any way to "Inscribe" a cell? I would like to run a macro on Enter keypress, that would execute different code depending on that "inscription" that would be invisible to user. I could use some properties of . Validation property like this:
Private Sub EnterPressed
'following code to ensure proper functioning of Enter in any other Worksheet
If ActiveSheet <> mySheet 'MySheet is global Variable then
ActiveCell.Offset(1,0).Select
exit Sub
End If
'now the real code
If ActiveCell.Validation.InputMessage = "1" Then
ActiveCell.Offset(0,1).Select
Else
'something else
End If
End Sub
The problem is, I use Data Validation and Conditional Formatting, so can't use any of these properties.
View 8 Replies
View Related
Feb 20, 2009
I'm trying to execute a macro and it won't put the focus (radio button) to select x pages wide by x pages tall in the Page Setup/Page/Scaling Area. I looked at the macro and can't find a setting in the code but yet the focus won't change. What can I do about this? In other words the radio button stays selected as "adjust to "" % of normal size. Here's the code...
View 2 Replies
View Related
Apr 17, 2009
I have below as part of my
Dim ToPath As String
ToPath = "C:Documents and Settings" & Environ("UserName") & "Desktop"
With Application.FileSearch
.LookIn = ToPath
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
Sheets("Sheet2").Range("A1:A65536").ClearContents
For i = 1 To .FoundFiles.Count
tempbuf = .FoundFiles(i)
tempbuf = Mid(tempbuf, InStrRev(tempbuf, "") + 1, 255)
Sheets("Sheet2").Range("A1").Offset(i, 0).Value = tempbuf
Next i
Else
Exit Sub
it exits the sub which apparently means .Execute is not > to 0.
So my question is, what does the line If .Execute() > 0 checks?
I am 101% sure that there are pdf files under the ToPath folder.
View 9 Replies
View Related
Feb 13, 2007
I'm using code from the Ozgrid page: http://www.ozgrid.com/VBA/loop-through.htm
However, once I get to the if statement If .Execute > 0... it does not contain a value. The folder contains 16 files in it, but .Execute does not recognize any of them. Is there a specific library or call that I'm missing??
I've been battling this for sooo long, I just dont know what to do with it.
View 9 Replies
View Related
Feb 24, 2014
Attachment 299651
I have turned a Workbook with Macros into an add-in. The macros work perfectly for the intended purpose: copy selected data in a special way and put it into an e-Mail message.
I used the CustomUI Editor to assign a macro to a Ribbon button.
However, when I turn it into an add-in and click the Ribbon button, it doesn't work on my machine or any other machine, with an error that says "Cannot run the macro 'CreateListofInventory'. The macro may not be available in this workbork or all macros may be disabled.
My macros are not disabled, and the add-in doesn't even work in the book where the macros reside.
View 2 Replies
View Related
Sep 25, 2009
I have two userform one if useing the getopenfilename to popluate a listbox. and then i use these listbox item withen this code to copy the files into a new folder. This works ok.
Then i copy a program into the same folder jpegresize.exe this program makes resized images of all files in its directory. by defult this program should only deal with these files. though what is happening is instead of using the files in the new folder it running on the files where the originals where copied from. (hope that makes sence). Though if i run jpegresize.exe from the new folder or command prompt it. It runs like it should. So i cant figure it out is there somethink the the shell and wait is passing that it shouldnt be.
View 3 Replies
View Related
Oct 15, 2009
I would like to execute a sub when the workbook is saved, what is the procedure for this.
View 3 Replies
View Related
Nov 6, 2009
How do I have a workbook execute VBA code when I hit 'Enter' anywhere on a specific sheet? I don't need the code to execute when I hit 'Enter' on any of the other sheets in the workbook, just a specific sheet.
View 11 Replies
View Related
Jan 13, 2010
I coudn't find anything on this forum on this subject.
Is there a way to execute [trigger] a macro from within a formula?
e.g. Based on an IF statement result, execute macro1 if true or macro 2 if false?
modytrane
View 7 Replies
View Related
Feb 3, 2003
I need a macro that will execute the F2 function key so that the cell can be edited.
View 7 Replies
View Related
Nov 19, 2011
I have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?
Sub DelRow()
With ActiveSheet
.AutoFilterMode = False
With Range("m1", Range("m" & Rows.Count).End(xlUp))
.AutoFilter 1, "false"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
View 2 Replies
View Related
Jun 17, 2008
I tried the following code but it shows an error:
Sub test2col()
Sheets("Sheet6").Cells.ClearContents
Sheets("Sheet6").Range("A:B").Value = Sheets("Sheet1").Range("A:B").Value
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub
It said
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub
has error.
Does a Sub not support to use Range more than one time? If so, do I need to write many Sub to do it?
View 11 Replies
View Related
May 18, 2009
How do I let a macro execute a certain key strok combination, such as Alt, D, G, H?
(Didn't really know what to search for...)
View 9 Replies
View Related
Jun 12, 2006
When the next empty cell in column A is selected, add a formula in the same row, column H. I'm not sure on how to hard code this and used the offset instead. So maybe instead of offsetting, i should/could change the references? However, as it is, it also adds the formla in column H when column G is selected and data is entered. I cant recreate this with any other column though.
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A5:A65000")) Is Nothing Then
If ActiveCell.Offset(-1, 0) = " r " Then
If ActiveCell.Offset(0, 7) = "" Then
ActiveCell.Offset(0, 7).Formula = "=if(RC[-1]="""","""",RC[-1]+120)"
Exit Sub
End If
End If
If ActiveCell.Offset(-1, 0) = "" Then
MsgBox "Please select the next empty cell/row!"
Exit Sub
End If
If ActiveCell.Offset(0, 7) = "" Then
ActiveCell.Offset(0, 7).Formula = "=if(RC[-1]="""","""",RC[-1]+120)"
End If
End If
End Sub
View 2 Replies
View Related
Sep 26, 2006
I need to create a batchfile from data retrieved from an excel spreadsheet.
1. I have 30 pre-select users on a list with their phone numbers and want to create checkboxes on each user to be selected.
2. Selected users will then be included in a batchfile to execute but only the corresponding phone numbers will be used.
3. Probably need to use a form for it to be user-friendly...i guess.
e.g. batchfile.bat
@ECHO OFF
::Location of the executable file:example.exe
d:
::CLI of utility
example 32165487 -tsve -g<ip> <msg>
example 45679821 -tsve -g<ip> <msg>
example 16543248 -tsve -g<ip> <msg>
View 9 Replies
View Related
Oct 29, 2006
Is is possible to have a button or a box of some sort that the user of a spreadsheet can click to execute a piece of vba code that I have? If so, can someone tell me how to insert such a button?
View 2 Replies
View Related
Oct 31, 2006
I'm doing a function to comprobate that a cell value has 11 digits. I'm not use only a validation because the the cell value can start with a 0. So I make this function
'This function is to get all the characters from a cell
Function ValidaSeguro(SS As String) As Boolean
Dim strArray() As String
Dim lLoop As Long, lCount As Long
Dim Respuesta As Integer
lCount = Len(SS)
If lCount <> 11 Then
ValidaSeguro = False
Respuesta = MsgBox("Don't have 11 digits")
Exit Function
End If
Redim strArray(lCount - 1)
For lLoop = 0 To lCount - 1.........................
View 4 Replies
View Related