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.
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.
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
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.
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.
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.
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
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
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?
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
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?
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.........................
I'm having a problem with negative values. Somehow if the pitchX is -11.1877, let's say, and it is the right value, the code will still perform the 2nd if statement, when it should not. Am I using the wrong data type? Or is there anything I'm missing out?
Dim pitchX As Double If pitchX > 10000 Then pitchX = pitchX / 1000 End If
If pitchX <> Range("C8").Value Then With Range("C8") .Font.Bold = True End With End If
i have columnar text that is organized by catagory and sub-catagory. what i would like to do is have a macro to hide/unhide rows containing text under sub-catagories by clicking on the sub-catagory and hide/unhide rows containing sub-catagories by clicking on the catagories.
I'm looking for a way to execute macros to hide/unhide rows according to catagory/sub-catagory and for this macro executer to hide/unhide as needed.
how to build and execute formulas and functions. My love for messing with excel started with an interest in personal financial management utilizing amoritzation tables, budget planning, paychecks, tax bases, etc., My wife sees it as strange but I love messing around with the Excel formulas. For now it's all self taught but, as stated, that will be changing.
So far, I haven't been able to find how to execute the following scenario.
For brief background, I'm attempting to identify the results of various outcomes of an individual currency trade by changing the investment size given the results of the last "x" amount of trades. Put another way, I'm running data sets on Forextester wherein I trade a historical period of time on a specific set of currencies, i.e. "Pound/Dollar." I'm wanting to know what the resulting balances would be, or would have been, if I implemented a money management strategy that increased my investment on consecutive trades when there was an "x" number of consecutive "wins" (ending account balance more than beginning) on the previous "x" number of trades. and decreased my investment when there was an "x" number of consecutive losses (ending account balance less than beginning account balance) on "x" number of trades...
So far, I've built the formula so that if I input the beginning and ending balance of a specific trade and Excel populates a "W" or "L" (Win or Loss) in the "Results:" Cell which was pretty simple. The following is one of three scenarios.
Strategy Conservative:
Start with risk 1% of Account balance (which is $10,000 for example)
The Rule: With each open trade reduce the account balance used by the amount risked on opened trade (For consecutive trades, assume current trade results in a total loss of investment. Thus, $100.00 of the $10,000 accounts means you're working with $9,900 on next trade)
The Rule: After 3 consecutive winners that make (1.8 * Risk percent used by the trade * account balance used by the trade) or greater in profit, increase risk to 1.5%
First trade Investment: $100.00 plus minimum of 80% gain. Second Trade Investment: $99.00 plus minimum of
80% gain. Third Trade Investment: $98.00 plus minimum of 80% gain. For trade number four, the investment amount would now be 1.5% of the total account balance.
After 1 loss reduce risk to 1% First Trade Investment $100.00 and you lose - size of loss doesn't matter. Next trade opens with investment of 1%.
After 2 consecutive losses reduce risk to 0.5%
First trade Investment $100.00 and you lose - size of loss doesn't matter. Next trade opens with investment of 1%. Second trade is also a loss. Thus, third trade invests 0.5% of total account balance.
After 4 consecutive losses reduce risk to 0.33%
After 2 consecutive wins that make (1.8 * 0.33%* account balance used by the trade) in profit, reset risk to 1% (Two wins = 1% investment, regardless of number of previous losses
There are two additional scenarios but they all follow the same pattern. The differences are only in the actual risk percentage. I can modify the formula as needed.
I found the following code to execute a macro in all excel files in a folder. Sounds amazing! I have a code to add to it, however I am having issues getting it to work. take a look at it and let me know what (more like, how many things). I am adding this to the Sheet 1 Worksheet.
Have an optimization question for you. I'm starting to try to optimize my macros and I've heard/read it's best to not activate or select anything. - I assumed that meant it would be more efficient to run code without it.
I have a loop I run through about 600 times that takes .75 to .85 seconds to run through with the following piece:
I would like to add a command to my macro that will do one simple step: Refresh all FDS Codes
FDS I believe is short for FactSet Data Series. FactSet is an add-in for excel we use at work. The FactSet menu button is in my ribbon and when I choose that add-in, there are a number of actions I can execute. One is to refresh all FDS which is to refresh all cells with formulas that pull in data from our FactSet database.
I tried recording this action but VBA does not show any key strokes from those steps so I think I just experienced one of the many shortfalls of recording macros. Is there a way to write the macro to execute this action? I would think since I am using a FactSet add-in, it would be possible but I don't know where to begin.
how to fill array with cells form selections and loop my macro for each cell of that array.
Code: 'this is macro I need to execute for each cell in my selection. Here I threat each cell from selection as solo selection.
Sub SELECTION_CELL_COUNT_SINGLE() Dim z As Integer, q As Integer, X As Boolean, I As Integer, txt As String Dim tmp As String, J As Integer, K As Integer Dim sStrip As String