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?
Related
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
I have an issue with my Excel workbook. I have code both in modules and embedded in the sheet.
Until recently, everything was working fine but suddenly the code embedded in the sheet does not work.
I have a sub routine for right clicked cells. This used to create a drop-down menu of its own rather than the standard right click menu but recently it stopped working. I have tried deleting the entire code and simply putting msgbox("Test"), but it still doesn't work.
Macros are enabled as this is the interesting thing ... if I right click the sheet tab and copy it ... the new version works absolutely fine. It is as if the original sheet has become corrupt.
This is further evidenced by when I try to delete the original sheet manually (right click tab and delete).
This causes Excel to crash.
I can delete any other sheet no problems.
However, a colleague of mine opened the workbook and it works fine for him without having to duplicate the sheet.
When it first happened I did the duplicate fix then renamed the original to "OBSOLETE". Not a pretty workaround, but worked nevertheless.
It has now happened again, however, and I am reluctant to keep patching it in this way.
If I try to address the sheet using VBA from another sheet:
Code in sheet 2 ("Slave"): msgbox(sheets("Master").cells(1,1).value)
it gives the following error:
Run-time error 32809: Application-defined or object-defined error
I have tried addressing it as sheet1.cells instead of sheets("Master").cells as well and this gives the same error.
Changing the code to point to Sheet3 works fine. It is literally just this sheet causing problems.
I tried 'open and repair' on the document too.
I have read around extensively and tried the deletion of .exd files etc. No luck.
Any thoughts? It seems independent of code - more a specific issue with this workbook and its sheet which over time becomes 'corrupt' but only for some machines/users.
There is also a command button in the sheet. This also does not work (clicking it just does nothing). If I go into the VBA editor and manually activate the sub-routine, I get the following error:
Compile error:
Object library invalid or contains references to object definitions that could not be found.
Again, this still happens even if I strip the code right down to a simple msgbox operation.
Any thoughts would be appreciated. Thanks
Hi i am having the same issue running code that populates combo boxes on my sheet. It seems that the sheet index is being deleted so the workbook o longer 'sees' the sheet you are trying to reference.
A simple workaround i found is to resave the workbook with a different name and it should work fine but this is not ideal when it is running on a regular basis. It does however allow you to recover the original workbook after it has been corrupted on the other machine.
It seems that some security updates made by microsoft in December 2014 have resulted in issues running sheets across the old and new machines. They are aware of the issue and are working to resolve it. This blog explains the issues and work arounds:
http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2014/12/11/forms-controls-stop-working-after-december-2014-updates-.aspx
Their solution provided on the above blog requires all users to have this update and then to delete all .exd files from the temp folder that are related to the issue and then recompile the code (this still requires all machines to have the new update).
Another option (the one I will be taking until they resolve the issue) is to roll back the problem machines to a pre Dec version prior to making the update.
Hope that helps!
I have a simple stored procedure that returns a Description and a Name when you give it a ID. I need to enable this inline in multiple Excel Sheets. Something like =ItemLookup('12345') that would then return the aforementioned info.
I have not done a lot with Excel programming and am simply wondering what my options are for tackling this. Is this a VBA thing or should this be an external DLL that I COM register? Both felt like overkill but then I realized I had no idea if they were. I really wanted to use VSTO for this but it sounds like that is not possible for Cell level UDF's without having to modifiy each Workbook with some VBA.
The best way to add UDF functions to Excel is with Excel-DNA (which is a free, open-source library I develop), and any of the .NET languages - VB.NET, C# and F# are all fine.
To get started you make a new 'Class Library' project in Visual Studio (any edition), install the 'Excel-DNA' package from the NuGet package manager, and add your code:
Public Module MyDataAccessFunctions
<ExcelFunction(Description:="Gets the Item from the database")>
Public Function ItemLookup(code As String) As String
' Here you have to do some work to get the data
Return "Hello " & code
End Function
End Module
Pressing F5 builds and starts Excel, and you're done - try putting =ItemLookup("Paladin") into a cell.
The resulting add-in is a single .xll file, which you can copy and use on any machine that has .NET without any installation or admin permissions. It works with old Excel versions too.
The best place for support (including absolute beginners' questions) is the Excel-DNA Google group.
You can use Excel to create a VBA UDF pretty easily, just hit alt+f8, right click your project in the project hierarchy on the left of the screen, and click add module.
Here is a quick Hello World function you can just paste into the module, then click play (or alt+f8 from worksheets)
sub test()
msgbox "helloworld"
end sub
If it was me, I would probably just create a list of the file paths that need to be searched. Then create a VBA macro that opens them in excel, searches them for the key, and returns other information from the row the key was found on.
You can open files with the 'Application.Open' method, simply pass in
the file path as an argument. 'Application.Open' returns a workbook
object.
Each workbook will have several worksheets, you can access them
through the workbook's 'Worksheet' property
Getting each used cell in a workbook can be done via looping through the 'UsedRange'
property in each worksheet
Get the value of a cell for comparison from the cell's 'value' property
Cells also have a 'row' property so you can find other items on the same row
If you're used to VBA you could get this running in less than an hour. But since you're just starting out it'll probably take a 3+ hours since you'll have more research/debugging
i have an issues with an macro that i'm writing. I have my xlsm file that i'm writing my macro in, it's creating a template that gets data from multiple spreadsheets that other people send me. However one file that i use for information is an xlsm file and is giving me problems. I believe i have isolated the problem but am unsure as to how to fix it.
the first sheet is named "Piranha" (no idea why), and the second sheet is named "Piranha - Dist & Growth split"
however when i write stardard code like
Sheets("Piranha").select
it has a runtime error 40036 (Application- defined or object defined error)
it also doesn't like
ActiveSheet.select / .name
but only for those two sheets, there is another sheet named "Exceptions" and i can use that object no problem. Has anyone ever heard of this problem or better have any ideas on how to solve it? Also because it's not my file if there is a way to do it without actually altering the file would be amazing. Thank you!
I had similar problem error 40036 and debugging pointed to a file path variable. When deleting or adding line of code the error moved...
I tried solution from Expert Exchange:
from VBA window do Debug>Compile VBAProject
fix any error raised
I fixed the error and it all works fine now :)
Thanks guys for your help, however i fiiiinally figured out that when trying to manipulate the file to get the data the macro of the file would interfere with my process, so i just make a copy of the file and delete all vb components and my code works fine
In the file which is a problem, try compiling the VBA project (via Debug > Compile VBA Project in the VBA editor) and see if there is an error in any code in the relevant sheet modules
Sub test()
Sheets("Sheet1 & 2").Select
ActiveSheet.Select
End Sub
Sub test2()
Sheets("Sheet1").Select
ActiveSheet.Select
End Sub
Tested your issue with the above code and I was unable to replicate your fault. Perhaps there is a space at the beginning or end of one of the sheets? As for ActiveSheet not working, it works OK in my test. I think you need to check your code, or at least update your Question with your code so we can check it
All these answers talk about compiling and clearing errors. If you're like me, you do that all the time. The answer didn't seem clear to me so here it goes:
Not only does your macro workbook need to be free of errors, so do ALL other workbooks you open. So if you're digging through a ton of data and you hit these bizarre object errors then it's possible there is a workbook with compile errors in your dataset. No amount of debugging your main workbook will fix the problem.
You have to be able to successfully compile every workbook you open programmatically. The OP said something about stripping "the vb components" out of his data. Any method like this you can do that avoids macros in your target data workbooks will work-around this issue. You can save each file as macro-free XLSX and then pull data from that. Or you could use ADO to access the data in a query.
I have the same problem and solved it by first finding which sheet was being accessed at the time of the error.
I copied all the data from that sheet (including formulas, formatting) and pasted into a new sheet along wit the sheet's VBA code. I deleted the old sheet and renamed the new set back to the old sheet.
On other words, I recreated everything back to what it was.
The error disappeared.
I have an Excel 2010 file (.xlsm) that contains code in a few modules including ThisWorkbook. The ThisWorkbook module contains a few Event procedures, including a _SheetActivate event.
I have a button on one sheet that, when clicked, activates a different sheet.
Today after working on some code in one of the regular modules, I clicked the button and got a
Run time error '-2147417848 (80010108)'
Method 'Activate' of object '_Worksheet' failed.
Any attempt to activate a different sheet (manually or programmatically) crashes the Application.
After some extensive research, all I found was this page which gives further information regarding the error:
-2147417848 (80010108): The object invoked has disconnected from its clients.
Resolving the error isn't so much of a concern to me because I don't need that particular event anymore. However, I do need to figure out why Excel keeps crashing. I tried to delete the code, but Excel crashed. So I tried commenting the code out, but Excel still crashed. Alas, everything I've tried has resulted in a crash. This leads me to believe that something must be corrupt in the script within that module (the code in other modules seems to work fine, but none of the other procedures activate a sheet).
I've read that an option would be to copy everything (including code) over to a new workbook, but I'd like to avoid that if possible as that would require copying more than the current sheet...but I can't copy the other sheets without Excel crashing. Does anyone have any ideas on how I could remove/delete the code from ThisWorkbook?
After too many crashes to count, I was finally able to resolve the issue.
First I copied the code (Ctrl + C) from ThisWorkbook that I wanted to be able to use later and pasted it into a blank notebook file. Then I did as Patrick suggested and exported the regular modules.
At this point, I tried programmatically removing the code, but Excel crashed again. Then it dawned on me that I didn't have to delete the code manually or programmatically; I just saved the file as an .xlsx document which by design removes the code.
From there I closed the file, opened it back up, and imported the .bas files I'd exported earlier. The last step before I saved the file in .xlsm format was to paste the copied code from the first step back into ThisWorkbook.
Everything works like a charm now. Thanks for the help! Cheers!