VBA IE.Document.All - vba

I'm running a very simple Excel VBA code that goes to a website, and fills in a form (thousands of similar posts out there), however I need the box it's filling out to change based on a cell in my Excel file.
Right now the line of code I'm trying is:
IE.Document.All(Worksheets("sheet1").Range("a1")).Value = Worksheets("sheet1").Range("a2")
However whenever I try running it, I get a runtime error saying "Object Required". I'm guessing the IE.Document.All(Worksheets("sheet1").Range("a1")) part is not how I'm supposed to do it, so I'm hoping someone can provide me with the right way (I'm very new to VBA). The program works fine if I repalce that part with the Name of the box on the form (from inspect element), or it also works if the box A1 just has text in it, however the box I'm trying to pull has a formula that puts together a string of text

Related

Excel VBA 2010 self reference a Active X button from within it's own action

i am trying to have an active X control in Excel 2010 get it's own alternate text and display it in a Text box when it is moused over.
If i use an absolute reference .Shapes("CommandButton1").AlternativeText it gets the text and i can do what i want with it, however i want a more dynamic function so the same code can be used on multiple buttons without edits so that it will always get the initiating button's own alt text.
I found this in my research, Self-referencing from inside an Excel VBA control
It seems like it would do what i need but when i run the module it throws a Runtime error 13, Type mismatch on this line Set shpButtons(btnCount).MyButton = shp.OLEFormat.Object.Object
If it matters i am trying to do this on a MouseMove event, however when i tested the code from the previous thread i was using direct clicks to see if it would would in the first place, which it did not, giving the Type mismatch error.
Any help getting this to work would be appreciated.
Thank you all so much in advance, lin.

Excel VBA: FormulaArray error when integrated with modeFRONTIER

I have a macro that works perfectly when I run it on Excel. It's basically something like:
Range("A1:A3").formulaArray = "=myFunction(input1, input2, input3)"
When I try to integrate this macro with modeFRONTIER, I receive the error message "Unable to set the FormulaArray property of the range class". One "solution" I managed is to substitute the commas for semi-colons to separate the inputs on the VBA code, the problem then is that it works as intended on modeFRONTIER but doesn't when used in Excel!
Another detail is that I tried in another computer with the same modeFRONTIER release, project, VBA code and spreadsheet and not even the first "solution" worked.
I know it's a very specific question, but anyone had this problem (or similar) when trying to integrate excel with different softwares?

Control Button to initiate the writing of a new VBA macro

Would it be possible to have a control button (or any mechanism) that once clicked on, a textbox would appear with fields like macro name Sub "NewMacroTitle"(), a field for the date, a field for reference sources ("Getting Links/URL from a webpage-Excel VBA"found this here"), a brief description of what the macro is to do. All of these fields, except Sub "NewMacroTitle"(), would start with a ' to show a comment and all of this would be inserted into the VBA editor, or enter it into cells on a spreadsheet that could then be copied and pasted into the VBA editor.
My problem is this. I'm new to VBA. I'm also the world's worst at documenting macros. I get an idea for a macro, I'm off into the VBA editor writing away, maybe even get the macro complete. A week later I'm reviewing the macro and the first thing is "what the heck does this thing do?"
I hope you see what I'm trying to do, essentially some way to force me to document the macro before even starting the actual code.
There are tools that will add pre-defined text to the header and/or footer of a sub. I use the one from MZ Tools for error handling code and adding my name and date to the header of each proc. It is worth a look.

Stop excel form debugging

I made a custom function in VBA, and when I called it from a cell, some error occurred. I am not able to edit the cell or save the file because excel is "debugging". If I try to edit excel cells, it gives a "beep", and if I try to save, it shows this dialog. I have tried pressing the blue square (reset) button in VBA many times. How do I stop this "debugging"?
Following is how VBA code looks like. The problem arose because I created a function named x(), and triggered it by calling ri() from a cell. After reading comments, I now know that I can stop debugging by renaming the function temporarily, but what is the right way to stop excel from "debugging"? I have also kept "Auto Syntax Check" unticked.
Following is the error message which appears on trying to save document.

How do you persistently format a TextBox to display a numeric value?

I'm sure this is a simple question, with a simple answer, but I can't find it.
I've inherited a spreadsheet that I have to fix. Whoever wrote it made extensive use of VBA and VBA UserForms for inputting data. On one form, textual and numeric information is entered and then saved to a record on a specific worksheet. This spreadsheet is used to log project information. It gets copied, and re-copied again and again. With each re-copy, it is cleared and used for the next project.
A user has sent me a spreadsheet of one of these major projects. The VBA, data-entry UserForm has a problem. One TextBox, which accepts either text or numbers, is always reformatting the numbers as dates when you exit the field!? I've tripled-checked the VBA code. There is no special OnEnter or OnExit code related to this field that reformats the data. Furthermore, I can't find a Format property that is associated with the TextBox from within the designer.
I'm a C/C# developer, not a VBA developer. Still, this "simple" IDE has me stumped. I can't find the property that re-formats the TextBox display value.
How can I fix the TextBox so that it persistently interprets numbers as numbers and not as dates?
FURTHER NOTE
It is worth mentioning two things. First, user's can't modify these forms or VBA code. The underlying modules are password protected and only myself and a couple managers know the password. Furthermore, no one touches the code because I'm the only developer within the company and everyone is a bit scare that they might break something.
Second, something in the file may have been corrupt. When this file was sent to me, the user also mentioned that the worksheet that he was working on was renamed. It appears that something didn't save properly because the WorkSheet tab was renamed a random hex string value.
Everything appears to be functioning as normal on this form, other than these two issues. Any help or guidance would be greatly appreciated.
You can force the proper format by using cLng:
First enter =TODAY() in cell A1 and then run:
Sub TextBoxIssue()
With ActiveSheet.Shapes("TextBox 1").TextFrame.Characters
.Text = Range("A1").Value
End With
MsgBox "However when we use cLng......"
With ActiveSheet.Shapes("TextBox 1").TextFrame.Characters
.Text = CLng(Range("A1").Value)
End With
End Sub
There is most certainly code that is formatting that text on exiting the textbox. You just haven't found it yet. If you go into the Userforms class module and select the textbox from the left dropdown, you can see all of the events in the right dropdown. The bolded events are in use. I assume you've already checked all those, but that's the place to start.
Next, look for custom class modules that use the WithEvents keyword. They can trigger events outside of the userform's class module.
Finally, search the code for all instances of =Format(tbxName.Text,"mm/dd/yyy") or some such code. Somewhere the code is probably using the Format function to fill that textbox.